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

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

Asked by 5 years ago

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

game.Players:GetPlayersAmount()

? please help, thanks :)

0
Simple game.Players.NumPlayers outlook1234567890 115 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago

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.

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

Ad
Log in to vote
0
Answered by
xEmmalyx 285 Moderation Voter
5 years ago

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"

0
thx CommanderCaubunsia 126 — 5y

Answer this question