When I code I usually will use game.Players:GetChildren()
but I was wondering if I should use :GetPlayers()
instead? Is there a difference between the two? If so, what are they?
Yes, :GetChildren
returns an array of everything inside (parent of game.Players).
:GetPlayers
returns an array of every player in the game (the player instance).
https://developer.roblox.com/en-us/api-reference/function/Players/GetPlayers
The only thing that will be in Players
are players. Am I correct?
Canonically, you would use GetPlayers
instead of GetChildren
for some readability improvement. Also somehow allows debugging faster if you know when GetPlayers
is called by searching for the term.
Also it does make a difference in case random instances somehow appear in the Players
service.
That’s usually the case, however it depends if people want to put stuff there or not.
Generally go with GetPlayers as it’s meant for players.
Is that even a word??? If it is, I’m impressed lol.