Is "player" a built-in parameter?

Hello, I’m stumped by as to why this script works:


local function onPlayerAdded(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local points = Instance.new("IntValue")
	points.Name = "Points"
	points.Value = 0
	points.Parent = leaderstats
end

Players.PlayerAdded:Connect(onPlayerAdded)

I don’t understand why the “player” parameter for the onPlayerAdded function is used after because it isn’t defined when the function is called. Is it built in?

1 Like

Yes, it is indeed a built-in parameter.

1 Like

Because in that local function you’re creating the player parameter, also the 1st parameter is always player

1 Like

What do you mean by the 1st parameter is always player?

player is a return of PlayerAdded, when the event is called, it returns the player who joined the game. The name of the parameter doesn’t have to be player, you could name it plr and it would still work after changing soem of the code around

1 Like

The parameter returns an instance of the player that joined the game.
More information here: Players | Roblox Creator Documentation

1 Like

Thank you very much! ! I understand it now.

2 Likes

It is the first parameter because that’s where the Player Added function is returning information through when a player joins

Like when you do Character in a Character Added it goes from Player to Player.Character

1 Like