Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Does the variable i use on leaderboards matter?

Asked by 6 years ago

in this code i was wondering if the variable 'player' in the event function must be that variable or it can be anything so what i mean is if i put in anything other than player as my variable would it still work or no?

--by Neosavvy

game.Players.PlayerAdded:Connect(function(player) 
    stats = Instance.new("IntValue", player) 
    stats.Name = "leaderstats" 

    Lvl = Instance.new("IntValue", stats)
    Lvl.Name = "Lvl"
    Lvl.Value = 0

    Nation = Instance.new("StringValue", stats)
    Nation.Name = "Nation"
    Nation.Value = "None"

    Rank = Instance.new("StringValue", stats)
    Rank.Name = "Rank"
    Rank.Value = "None"
end)
0
You can rename `player` to anything long as it agrees with lua syntax. EpicMetatableMoment 1444 — 6y
0
Be careful when naming two things with the same variable because one will overwrite the other EpicMetatableMoment 1444 — 6y
0
You can name it whatever you want. But it is encouraged that you use variable names that make sense based on the situation you're in. In this case you're dealing with a player "player" is appropriate User#24403 69 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Yes you can put anything other than "player"

Variables can be set to almost anything. The first argument passed to the function connect to the event for PlayerAdded is the reference to the player instance.

You can set the variable's name to anything that lua syntax agrees with.

Example

local players = game:GetService("Players")

local function playerAdded(epic)
    print(epic)
end

players.PlayerAdded:Connect(playerAdded)

In this case the variable epic in the connected function playerAdded's scope is the reference to the newest player added.

Ad

Answer this question