API:Class/Players/PlayerAdded

< API:Class‎ | Players(Redirected from PlayerAdded)

PlayerAdded

Event of Players icon.pngPlayers
RBXScriptSignal PlayerAdded (
    Player player
)
Parameters:
  1. player

Description: Fires when a player enters the game.

Notes

  • Up until recently, this event didn't work on the client (in localscripts), but this has been changed
  • This event does not work as expected in solo mode, because the player is created before scripts that connect to PlayerAdded run. To handle this case, as well as cases in which the script is added into the game after a player enters, create an OnPlayerAdded function that you can call to handle a player's entrance.
local Players = game:GetService("Players")
 
function onPlayerAdded(player)
     print(player.Name .. " has entered the game")
end
 
--When a player joins, call the onPlayerAdded function
Players.PlayerAdded:connect(onPlayerAdded)
 
--Call onPlayerAdded for each player already in the game
for _,player in pairs(Players:GetPlayers()) do
     onPlayerAdded(player)
end

Example

game.Players.PlayerAdded:connect(function(player)
	print("A player has entered: " .. player.Name)
end)