Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is the difference between these to get the players?

Asked by 4 years ago

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?

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. Rinpix 639 — 4y
1
add your comment as an answer. ScuffedAI 435 — 4y
0
thanks! Fr0stPh3onix 79 — 4y
1
I know that I could've added it as an answer but it'd just seem like I'm farming reputation points, lol. Rinpix 639 — 4y

1 answer

Log in to vote
2
Answered by 4 years ago

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.

Ad

Answer this question