Jump to content

[Help] attempt to perform arithmetic on global


GERgta

Recommended Posts

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...