How do I make a script that finds the amount of players and when there is 2 + players online will start a countdown. I don't need help on the countdown part, I just need help on finding the amount of players online and triggering something to happen when the amount of players reaches 2+
✓ ANSWER ACCEPTED
Amount Of Players Online your game?
2 answers
✓ Accepted answer
The Players service has a property NumPlayers, the number of players currently playing in that place.
Alternatively, you can compute this on your own using #game.Players:GetPlayers() to get the number (# is table length) of players playing.
Since this is just a number, you can compare using "greater than or equal to", >= and 2. (or > 1)
This check could be done continously (in some loop), or by using the PlayerAdded event.
Give me a second I need to write it
EDIT:
local CountPlayers=(function()
local Count=0
local Player=game.Players:GetPlayers()
if (#Player>0) then
for p=1,#Player do
if (Player[p].Character) then
Count=Count+1
end end end
return Count end)
while true do
wait(3)
if (CountPlayers() >=2) then
--- script to start the game.
else
m=instance.new("Message")
m.Parent=game.Workspace
m.Text=("Another player is needed to play...")
end
end
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Did that help? If so give me 1+ rep.