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

How to make game wait for enough players?

Asked by 4 years ago

Currently making a game and I want a script to wait before there are at least 4 players before it begins the round.

round = false
local hint = Instance.new("Hint")

while round == false do
    if script.Parent.val.Value < 5 then
        hint.Parent = game.Workspace
        hint.Text = "Waiting for Players"
    else
        hint.Parent = game.Workspace
        hint.Text = "Game Will Begin Shortly"
        round = true
    end
end

val is the name of the value which contains the playercount number, it's working fine, whenever I change the intvalue to a number over 5, the script works and the game begins, however, when I try changing the intvalue during the game, It gets stuck on the "Waiting for Players" part.

0
when u directly change it from properties in explorer it doesn't register HappyTimIsHim 652 — 4y

2 answers

Log in to vote
1
Answered by
Benbebop 1049 Moderation Voter
4 years ago

To get a reading of how many players are in the game see how many children game.Players has. This can be done as follows,

Ex.

local CurrentPlayers = game.Players:GetChildren()
local PlayerCount = #CurrentPlayers

# is used to get a count of how many values are in a table which we created with GetChildren. In this case the table is filled with each player’s instance.

Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
if game.Players.NumPlayers > 3 then -- if the there is more than 3 players then 
-- Do whatever
end

Answer this question