I haven’t found any posts about this elsewhere, so I will ask it here. What exactly is the difference between GetPlayers() as opposed to GetChildren(). I know GetPlayers only returns player objects, whilst GetChildren returns all the children of a specified parent. However, in the case of using it under the service “Players”, there literally is no difference.
For example, I know a lot of people who did this…
game.Players:GetChildren()
compared to this…
game.Players:GetPlayers()
What use does this have over the other, it’s applicable for other uses such as workspace or ect, but for players?
That is what I’m asking. Technically they both get players under the service “Players”, so what is the difference. As far as I know, the only thing that exists under is “Players” is literally players.
Both of those achieve the same thing. GetChildren gets everything inside the place where you want. GetPlayers only gets the Players. There are only player objects in game.Players so GetChildren will also get all the players.
GetPlayers() returns player objects in the Player’s service while GetChildren() get’s everything, even non player objects in the Player’s service if found.
There aren’t. If there are, :GetChildren() will return them as well. I did mentioned ‘if found’.
for _, v in ipairs(game.Players:GetChildren()) do
print(v) -- print everything inside the players service
end
for _, v in ipairs(game.Players:GetPlayers()) do
print(v) -- will only print if a player object found
end
Say a script parents something to Players, :GetChildren() will find that child. :GetPlayers() only gets the players, which means it will not find that specified child the script added to Players.
So both ways get any child of the service. I understand that one Gets player objects, whilst the other gets every child. Since they both get the same thing, is there any differences?
For example
--Players-- Get every child inside
Player1
Player2
--Players-- Gets all player objects inside
Player1
Player2
You can see that they both get players. There is no difference, except for checking whether or not player object exist or not. They both get the players regardless.
Player’s service will only have players, but by chance people can insert something inside the Players service. :GetChildren() will return everything inside it while :GetPlayers() will return only players.
Of course :GetChildren() will return the players because there are players inserted to the Player’s service, if there were for e.g a CFrame object, :GetChildren() will also return the CFrame object.
That’s also the reason why :GetPlayers() is better.
Thankyou everyone for clarifying this. I always use GetPlayers under the Player’s Service, instead of the other, obviously.
I just don’t see the use for getchildren over getplayers under the service. I understand the functions and what they get, but they both still return players under the service. Since, players should be the only thing to exist, regardless. As @ArrantNickel mentioned you can create objects to store under the player and get that using GetPlayers, but that’s really the only reason why. I don’t see any other uses.
And hardly anyone stores objects under the service.