Noah_Antilles Posted June 21, 2017 Posted June 21, 2017 (edited) Hello! I have almost finished a script, but I have some trouble figuring this problem: What I want to do is to save a certain vehicleComponent's rotation, and call on that rotation/value later on. But I get the error: Attempt to perform arithmetic on global 'ox' (a nil value) From what I can see the setElementData doesn't save the original value for some reason. setElementData should save the rotation of "gear_f" here under the name "ox" (original rotation on x-axis) function shamalDisableGear() local vehicle = getPedOccupiedVehicle(localPlayer) local ox = getVehicleComponentRotation(vehicle, "gear_f") -- should save it here local originalRotation = setElementData(vehicle, "gear_f", ox, true) -- should save it here if(vehicle)then if getElementModel(vehicle) == 519 then toggleControl ("sub_mission", false) end end end addEventHandler ( "onClientPlayerVehicleEnter", getLocalPlayer(), shamalDisableGear ) Later on, when the setElementData is called by getElementData: function shamalGearFront(button, press) local vehicle = getPedOccupiedVehicle(localPlayer) if(vehicle)then if getElementModel(vehicle) == 519 then if button == "2" and (press) then if gearstate == 0 then local rx, ry, rz = getVehicleComponentRotation(vehicle, "gear_f") setTimer(function () rx = rx - 3 if rx < 0 then rx = 360 - rx end setVehicleComponentRotation(vehicle, "gear_f", rx-3, ry, rz) end,50,33) elseif gearstate == 1 then if getElementData(vehicle, "gear_f", ox, true) then -- it seems it doesn't save the original value (ox) setVehicleComponentRotation(vehicle, "gear_f", ox-90, oy, oz) setTimer(function () rx = rx +1 setVehicleComponentRotation(vehicle, "gear_f", rx+1, ry, rz) end,50,90) end end end end end end addEventHandler ( "onClientKey", root, shamalGearFront ) What is causing this problem? Thanks in advance for your help, -Noah Edited June 21, 2017 by Noah_Antilles
Moderators IIYAMA Posted June 21, 2017 Moderators Posted June 21, 2017 local ox = getElementData(vehicle, "gear_f") -- ox can be used after here if ox then -- isn't it false or nil? end getElementData has a different syntax than setElementData. Check wiki pls. 2 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Noah_Antilles Posted June 22, 2017 Author Posted June 22, 2017 @IIYAMA Thanks again mate, small mistake I hadn't seen. It works now 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now