Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Does the variable i use on leaderboards matter?

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)

3 comments

0

You can rename player to anything long as it agrees with lua syntax.

0

Be careful when naming two things with the same variable because one will overwrite the other

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

1 answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.