I have seen Scripts where Users would use the "ChildAdded" instead of the PlayerAdded
when a Player joins the Server, for Example:
game.Players.ChildAdded:connect(function(chl) print(chl.Name.." Has joined the game" end)
This also works for Models, Parts, etc When moved to Workspace(or any other Containers).
But In most Scripts users would Use the PlayerAdded
Which on the other hand Picks-up the Player THAT Joined the Server, Here is an Example:
game.Players.PlayerAdded:connect(function(plr) print(plr.Name.." Has Joined the game" end)
Which is Better to use, and why?
According to this, you would typically use PlayerAdded
in a server script, whereas ChildAdded
can be used either in a local or server script, because its use is more broad.
There's almost no difference between the two events. But if you were to test two server scripts with different events, be sure that you are adding nothing to game.Players
, else the ChildAdded
will fire (and the PlayerAdded
event will not).
In addition to what Redbullusa stated,
PlayerAdded
only fires when a player was inserted into Players, whereas ChildAdded
would fire whenever your put anything in Players, such as a Part, or Model.
Same thing with game.Players:GetChildren()
. That gets all children, and then handy dandy game.Players:GetPlayers()
only gets the Player objects in Players.