Heres the script, my problem is that the game duration is suppose to count down when the game starts but instead, after it says Go, it says “Game Starting” but I want it to count down the game duration. Hopefully someone can help me
local status = game.ReplicatedStorage.Status
local intermission = 2
local gameDuration = 60
while true do
local IngamePlayers = {}
local gameEnded = false
while wait(1) do
status.Value = "Waiting for enough players. Hop on the pink circle to begin."
for _, player in pairs(game.Players:GetPlayers()) do
if player.Info:FindFirstChild("IsPlaying").Value == true and not table.find(IngamePlayers, player.Name) then
table.insert(IngamePlayers, player.Name)
end
end
if #IngamePlayers >= 1 then
break
end
end
-- choosing next game
status.Value = "Game starting..."
wait(2)
for i = intermission,0,-1 do
status.Value = "Teleporting in "..i.. " seconds"
wait(1)
end
status.Value = "Teleporting Players..."
wait(1)
for _, player in pairs(game.Players:GetPlayers()) do
if table.find(IngamePlayers, player.Name) and player.Info:FindFirstChild("IsPlaying").Value == true then
local randomSpawn = redLightGreenLight["Spawns"]:GetChildren()[math.random(1, #redLightGreenLight["Spawns"]:GetChildren())]
player.Character.HumanoidRootPart.CFrame = randomSpawn.CFrame
end
end
wait(2)
for i = 5,0, -1 do
status.Value = "Starting in " ..i
wait(1)
end
status.Value = "Go!"
wait(1)
spawn(function()
while true do
for i, v in pairs(game.Players:GetPlayers()) do
if v.Info:FindFirstChild("IsPlaying").Value == true then
v.PlayerGui.Main.LightColor.Visible = true
v.PlayerGui.Main.LightColor.Text = "Green Light"
v.PlayerGui.Main.LightColor.TextColor3 = v.PlayerGui.Main.LightColor.GreenLightColor.Value
end
end
while not gameEnded do
for i, v in pairs(game.Players:GetPlayers()) do
if v.Info:FindFirstChild("IsPlaying").Value == true then
v.PlayerGui.Main.LightColor.Text = "Red Light"
v.PlayerGui.Main.LightColor.TextColor3 = v.PlayerGui.Main.LightColor.RedLightColor.Value
end
end
wait(math.random(2,4))
for i, v in pairs(game.Players:GetPlayers()) do
if v.Info:FindFirstChild("IsPlaying").Value == true then
v.PlayerGui.Main.LightColor.Text = "Green Light"
v.PlayerGui.Main.LightColor.TextColor3 = v.PlayerGui.Main.LightColor.GreenLightColor.Value
end
wait(math.random(1,6))
end
end
for i = gameDuration,0,-1 do
status.Value = i.. " seconds remaining"
wait(1)
end
gameEnded = true
end
end)
end
local status = game.ReplicatedStorage.Status
local intermission = 2
local gameDuration = 60
while true do
local IngamePlayers = {}
local gameEnded = false
while wait(1) do
status.Value = "Waiting for enough players. Hop on the pink circle to begin."
for _, player in pairs(game.Players:GetPlayers()) do
if player.Info:FindFirstChild("IsPlaying").Value == true and not table.find(IngamePlayers, player.Name) then
table.insert(IngamePlayers, player.Name)
end
end
if #IngamePlayers >= 1 then
break
end
end
-- choosing next game
status.Value = "Game starting..."
wait(2)
for i = intermission,0,-1 do
status.Value = "Teleporting in "..i.. " seconds"
wait(1)
end
status.Value = "Teleporting Players..."
wait(1)
for _, player in pairs(game.Players:GetPlayers()) do
if table.find(IngamePlayers, player.Name) and player.Info:FindFirstChild("IsPlaying").Value == true then
local randomSpawn = redLightGreenLight["Spawns"]:GetChildren()[math.random(1, #redLightGreenLight["Spawns"]:GetChildren())]
player.Character.HumanoidRootPart.CFrame = randomSpawn.CFrame
end
end
wait(2)
for i = 5,0, -1 do
status.Value = "Starting in " ..i
wait(1)
end
status.Value = "Go!"
wait(1)
while true do
for i, v in pairs(game.Players:GetPlayers()) do
if v.Info:FindFirstChild("IsPlaying").Value == true then
v.PlayerGui.Main.LightColor.Visible = true
v.PlayerGui.Main.LightColor.Text = "Green Light"
v.PlayerGui.Main.LightColor.TextColor3 = v.PlayerGui.Main.LightColor.GreenLightColor.Value
end
end
while not gameEnded do
for i, v in pairs(game.Players:GetPlayers()) do
if v.Info:FindFirstChild("IsPlaying").Value == true then
v.PlayerGui.Main.LightColor.Text = "Red Light"
v.PlayerGui.Main.LightColor.TextColor3 = v.PlayerGui.Main.LightColor.RedLightColor.Value
end
end
wait(math.random(2,4))
for i, v in pairs(game.Players:GetPlayers()) do
if v.Info:FindFirstChild("IsPlaying").Value == true then
v.PlayerGui.Main.LightColor.Text = "Green Light"
v.PlayerGui.Main.LightColor.TextColor3 = v.PlayerGui.Main.LightColor.GreenLightColor.Value
end
wait(math.random(1,6))
end
end
for i = gameDuration,0,-1 do
status.Value = i.. " seconds remaining"
wait(1)
end
gameEnded = true
end
end
I’m pretty sure spawn is deprecated, and coroutine is better in general, so it’s better to use that. Also, I’m not going to take the time to go through this fully, sorry, but I recommend changing all of the wait()'s to task.wait() as wait() is deprecated and lastly, all of the while true do’s should be in coroutines as to not prevent the rest of the code from happening.
local status = game.ReplicatedStorage.Status
local intermission = 2
local gameDuration = 60
while true do
local IngamePlayers = {}
local gameEnded = false
coroutine.resume(coroutine.create(function()
while wait(1) do
status.Value = "Waiting for enough players. Hop on the pink circle to begin."
for _, player in pairs(game.Players:GetPlayers()) do
if player.Info:FindFirstChild("IsPlaying").Value == true and not table.find(IngamePlayers, player.Name) then
table.insert(IngamePlayers, player.Name)
end
end
if #IngamePlayers >= 1 then
break
end
end
end))
-- choosing next game
status.Value = "Game starting..."
wait(2)
for i = intermission,0,-1 do
status.Value = "Teleporting in "..i.. " seconds"
wait(1)
end
status.Value = "Teleporting Players..."
wait(1)
for _, player in pairs(game.Players:GetPlayers()) do
if table.find(IngamePlayers, player.Name) and player.Info:FindFirstChild("IsPlaying").Value == true then
local randomSpawn = redLightGreenLight["Spawns"]:GetChildren()[math.random(1, #redLightGreenLight["Spawns"]:GetChildren())]
player.Character.HumanoidRootPart.CFrame = randomSpawn.CFrame
end
end
wait(2)
for i = 5,0, -1 do
status.Value = "Starting in " ..i
wait(1)
end
status.Value = "Go!"
wait(1)
coroutine.resume(coroutine.create(function()
coroutine.resume(coroutine.create(function()
while true do
for i, v in pairs(game.Players:GetPlayers()) do
if v.Info:FindFirstChild("IsPlaying").Value == true then
v.PlayerGui.Main.LightColor.Visible = true
v.PlayerGui.Main.LightColor.Text = "Green Light"
v.PlayerGui.Main.LightColor.TextColor3 = v.PlayerGui.Main.LightColor.GreenLightColor.Value
end
end
end))
coroutine.resume(coroutine.create(function()
while not gameEnded do
for i, v in pairs(game.Players:GetPlayers()) do
if v.Info:FindFirstChild("IsPlaying").Value == true then
v.PlayerGui.Main.LightColor.Text = "Red Light"
v.PlayerGui.Main.LightColor.TextColor3 = v.PlayerGui.Main.LightColor.RedLightColor.Value
end
end
wait(math.random(2,4))
for i, v in pairs(game.Players:GetPlayers()) do
if v.Info:FindFirstChild("IsPlaying").Value == true then
v.PlayerGui.Main.LightColor.Text = "Green Light"
v.PlayerGui.Main.LightColor.TextColor3 = v.PlayerGui.Main.LightColor.GreenLightColor.Value
end
wait(math.random(1,6))
end
end
for i = gameDuration,0,-1 do
status.Value = i.. " seconds remaining"
wait(1)
end
gameEnded = true
end))
end
end))
end