PlayerAdded (Event)

From Legacy Roblox Wiki
Revision as of 01:42, 18 April 2023 by GuestIsJustBest (talk | contribs) (Better code)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search
PlayerAdded ( Player player )
Description Fired after a player enters the game.
Member of: Players


Example

This code will print A player has entered: , followed by the player's name, everytime a player enters:

local Players = game:GetService("Players")

local function onPlayerAdded(player)
	print("A player has entered: " .. player.Name)
end

Players.PlayerAdded:connect(onPlayerAdded)


Note: This method does not work as expected in solo mode, because the player is created before scripts that connect to PlayerAdded run. To fix this problem during solo add this to the end of a script:
for _, player in ipairs(Players:GetPlayers()) do
	onPlayerAdded(player)
end

See Also