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

How to detect how many players there are in a game?

I must know how to detect how many players there are, is there something like

game.Players:GetPlayersAmount()

? please help, thanks :)

1 comment

0

Simple

game.Players.NumPlayers

2 answers

✓ Accepted answer

There is a function of Players which is :GetPlayers(). It returns an array of all the players in the game. This can be used in conjunction with the unary length operator #. The length operator can be used to get the length of a table or string. The length of the table is however many elements there are in it.

print(#game:GetService("Players"):GetPlayers());

I believe there are 2 ways to go about this There is a built-in function

#game.Players:GetPlayers()

and

#game.Players:GetChildren()

I'd recommend using the built-in function which I believe is just an alternative of "GetChildren"

1 comment

0

thx

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