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

How to count connected players?

Asked by 10 years ago

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

Log in to vote
0
Answered by
Sublimus 992 Moderation Voter
10 years ago

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

print(#game.Players:GetChildren()) -- Would print number of players
Ad
Log in to vote
0
Answered by
Kozero 120
10 years ago

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

print(#game.Players:GetPlayers())
Log in to vote
0
Answered by 10 years ago

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.

Log in to vote
0
Answered by
Redbullusa 1580 Moderation Voter
9 years ago

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

print(game.Players.NumPlayers)
0
This is from 8months ago. KnownDev 0 — 9y
0
¯\_(:/)_/¯ Redbullusa 1580 — 9y

Answer this question