GERgta Posted December 12, 2013 Share Posted December 12, 2013 Hello forums once again. I've tried to script some performance parts for cars and somehow the variable doesn't get set. I searched google and nothing helped me. Maybe YOU can spot the error? function upgradeMotor ( playerSource ) local theVehicle = getPedOccupiedVehicle ( playerSource ) local seat = getPedOccupiedVehicleSeat ( playerSource ) if seat == 0 then if getElementData(theVehicle, "upgradeMotor") then local motorUpgrade = getElementData(theVehicle, "upgradeMotor") else local motorUpgrade = 0 end local buyingMotorUpgrade = motorUpgrade + 1 if buyingMotorUpgrade < 3 then local price = buyingMotorUpgrade * 2000 local playerMoney = getPlayerMoney ( playerSource ) if playerMoney > price then setPlayerMoney ( playerSource, playerMoney - price ) setElementData ( theVehicle, "upgradeMotor", buyingMotorUpgrade ) outputChatBox ("Motor-Upgrade " ..buyingMotorUpgrade.. " buyed for " ..price.. "$!", playerSource) outputChatBox ("You may need to re-enter your car to let the changes apply.", playerSource) else outputChatBox ("You dont have enough Money! The price is " ..price.. "$!", playerSource) end else outputChatBox ("This car doesn't support more motor upgrades!", playerSource) end else outputChatBox ("Only drivers can buy upgrades!", playerSource) end end addCommandHandler ( "upgrademotor", upgradeMotor ) Console output: server.lua:13: attempt to perform arithmetic on global 'motorUpgrade' (a nil value) Link to comment
Castillo Posted December 12, 2013 Share Posted December 12, 2013 That's because you have set the variable as local, that means it won't exist outside the 'if' statement. Link to comment
GERgta Posted December 12, 2013 Author Share Posted December 12, 2013 That's because you have set the variable as local, that means it won't exist outside the 'if' statement. Thanks for that info, i'll see what I can do. Link to comment
Castillo Posted December 12, 2013 Share Posted December 12, 2013 All you have to do is remove 'local' from infront of it. Link to comment
GERgta Posted December 12, 2013 Author Share Posted December 12, 2013 All you have to do is remove 'local' from infront of it. That's what I did: it works now Wont there be conflicts if one than more player executes the command at the same time? Link to comment
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