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

How do you check if there are enough players?

What I mean is: The game waits until 4 players are in the server, then continues on. I tried to find a command for this, but it came up with nothing of the sort. Instead I got things like to check how many players are playing the game in total. I've seen games where if there isn't enough players it says, "Waiting for players..." I want to do this as well, but I cannot find a command for it. Maybe there is an alternative, such as checking how many players are in an area, such as a lobby.

1 answer

✓ Accepted answer

This is done by evaluating the length of an array containing all current Player Objects.

You can achieve that with the GetPlayers method, paired with the length operator:

local Players = game:GetService("Players")

print("Number of Player(s) in-game: "..#Players:GetPlayers())

You can integrate this code snippet into a repeat wait() clause to yield the progression of your main program until the requirement is met:

local Players = game:GetService("Players")

local PlayerCountRequirement = 4


repeat wait() until #Players:GetPlayers() >= PlayerCountRequirement

2 comments

0

how would it look like when a repeat wait() is added? Do I use repeat wait() until? or do I perform something different?

0

Thanks for this!

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