Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What is the difference between these to get the players?

What is the difference between

game.Players.PlayerAdded
game.Players.LocalPlayer
game:GetService("Players")
game.Players:GetPlayers()

Is there any other way to get players? What can i use each for?

4 comments

1

PlayerAdded is an event that fires when a player joins the game. game.Players.LocalPlayer is a quick way of getting the player that the script is running on. It can only be used inside of a LocalScript that is inside of a player. game:GetService("Players") is just a way of accessing the Players service. :GetPlayers() returns a table containing all of the players currently connected to the server.

1

add your comment as an answer.

0

thanks!

1

I know that I could've added it as an answer but it'd just seem like I'm farming reputation points, lol.

1 answer

✓ Accepted answer

Game.Players.PlayerAdded is an event that fires when a new player joins the game.

Game.Players.LocalPlayer only works in a local script, and it returns the local client.

game:GetService("Players") returns the player service, which is the same thing as doing game.Players.

game.Players:GetPlayers() returns an array of all players currently in the game.

This discussion is preserved as it was. New answers, comments, and votes are closed.