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

How to make game wait for enough players?

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.

1 comment

0

when u directly change it from properties in explorer it doesn't register

2 answers

✓ Accepted answer

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.

if game.Players.NumPlayers > 3 then -- if the there is more than 3 players then 
-- Do whatever
end

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