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

Amount Of Players Online your game?

Asked by
Bman8765 270 Moderation Voter
10 years ago

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+

2 answers

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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.

Ad
Log in to vote
-2
Answered by 10 years ago

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
0
Did that help? If so give me 1+ rep. PancakeAttacks 0 — 10y

Answer this question