Getting a variable from another player

Status
Not open for further replies.

amperbee

thunderdome denizen
I made a local variable "fuel".

I'm making a command letting you exchange "fuel" with other players.
The problem I'm having is that everytime I try to check for player.fuel (player is already the userdata of someone, I took a function from Terminal) it tells me it's nil.
I can get the player name, but not the fuel variable.
How do I get the variable?
 
Last edited:
I don't think you have to declare a local variable before the rest of the script, if "fuel" is going to be something that can have different values for each player.

Rather, you have to first declare (and give a value to) player.fuel for every player (with an iterate), and only then you'll be able to check each player's fuel.

Something like this:
Code:
addHook("ThinkFrame", function()
    for player in players.iterate do

        if not player.fuel then player.fuel = 0 //you can make the default fuel given on spawn any number you want
        end

    end
end)
 
Last edited:
I don't think you have to declare a local variable before the rest of the script, if "fuel" is going to be something that can have different values for each player.

Rather, you have to first declare (and give a value to) player.fuel for every player (with an iterate), and only then you'll be able to check each player's fuel.

Oh, okay! Thanks.
 
Status
Not open for further replies.

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top