There are quite a few ways to count all the Players. Personally, I just use the Property in game.Players NumPlayers. It has the exact number of Players on the server.
For example:
1 | Players = Game.Players.NumPlayers |
But I guess another way is:
1 | Players = #Game.Players:GetChildren() |
3 | Players = #Game.Players:children() |
but that way gets things like String Values and anything else n Players, so it's better to use this:
1 | Players = #Game.Players:GetPlayers() |
But I guess if you want to make a more complex way of counting all the players and completely waste your time, you could make functions for when Players Join and Leave and then Add/Minus 1 each time, like this:
~~~~~~~~~~~~~~~~~
NumberOfPlayers = 0
function NewPlayer(New)
NumberOfPlayers = NumberOfPlayers + 1
end
Game.Players.PlayerAdded:connect(NewPlayer)
function LessPlayer(Old)
NumberOfPlayers = NumberOfPlayers - 1
end
Game.Players.PlayerRemoving:connect(LessPlayer)
~~~~~~~~~~~~~~~~~
but I prefer to use Game.Players.NumPlayers, because it's a lot easier.
Well, I hope this was useful at all.
** - Kratos232**