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

How do you check if there are enough players?

Asked by 3 years ago

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

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

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
0
how would it look like when a repeat wait() is added? Do I use repeat wait() until? or do I perform something different? User#37681 0 — 3y
0
Thanks for this! User#37681 0 — 3y
Ad

Answer this question