Jump to content

nil with number


Drakath

Recommended Posts

I tried debugging it with: outputChatBox ( tostring ( cost ) )

But all results outputted a number just like tonumber(cost)

I'm not sure how do players manage to make this error.

Also when I added this line: if not tonumber(cost) == nil then I couldn't buy it anymore.

Link to comment

Are you sure that you're trying to receive the money of the right person? I've had trouble with this too, but that was because my money was... oh well... 0. ^^" ( without tonumber, this will also give you an error. )

You should try to see what 'source' is:

outputDebugString ( getPlayerName ( source ) ) 

Link to comment
  • Moderators

well if it output always correct, then it should work.

The most secure way would be:

local cost= tonumber(cost) 
local money = getPlayerMoney (source) 
if cost and money then 
    if money >= cost then 
        outputDebugString("works") 
    else 
        outputDebugString("not enough money") 
    end 
else 
    outputDebugString("cost or money do not exist.") 
end 
  

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...