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

How to count connected players?

I want to create a script that would count how many players are current IN the game and connected, this will help me create a minigame script that knows not to start if there's not a certain number.

4 answers

Just use the :GetChildren() of the player service:

print(#game.Players:GetChildren()) -- Would print number of players

Or you could do this by using the GetPlayers() method.

print(#game.Players:GetPlayers())

What about not allowing the script to start without players? Would that be

if #game.Players:GetChildren == 5 then
 message.Text = ("Starting Game!")

elseif #game.Players:GetChildren == >5 then
 message.Text = "We need " ..players

Obviously will create the ..players var but just for reference.

There's a read-only NumPlayers property in Players.

print(game.Players.NumPlayers)

2 comments

0

This is from 8months ago.

0

¯_(:/)_/¯

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