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 5 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.

01round = false
02local hint = Instance.new("Hint")
03 
04while round == false do
05    if script.Parent.val.Value < 5 then
06        hint.Parent = game.Workspace
07        hint.Text = "Waiting for Players"
08    else
09        hint.Parent = game.Workspace
10        hint.Text = "Game Will Begin Shortly"
11        round = true
12    end
13end

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 — 5y

2 answers

Log in to vote
1
Answered by
Benbebop 1049 Moderation Voter
5 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.

1local CurrentPlayers = game.Players:GetChildren()
2local 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 5 years ago
Edited 5 years ago
1if game.Players.NumPlayers > 3 then -- if the there is more than 3 players then
2-- Do whatever
3end

Answer this question