API:Class/Players/PlayerAdded

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

PlayerAdded

Event of Players icon.pngPlayers
There are members of the same name. See the disambiguation page.
RBXScriptSignal PlayerAdded (
    Player player
)
Parameters:
  1. player

Description: Fires when a player enters the game.
Disambig redirect page does not exist - create it
Disambig page is improperly set up - if you are an editor, copy the contents of this page, and paste it as the contents of this page.

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)