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

Countdown stops in the game, how do I fix this?

I'm making a break system for my game, but the countdown stops every time I test the game.

The script I've made so far:

local timer = game.StarterGui.Timer.TimerText
local lobbyMusic = game.Workspace.Sounds.Intermission
local inGameMusic = game.Workspace.Sounds.InGame

local storage = game:GetService("ReplicatedStorage")

local intermissionCountdown = storage.Values.IntermissionCounter
local ingameCountdown = storage.Values.InGameCounter
local status = storage.Values.Status

local maps = storage.Maps

if status.Value == "Intermission" then
	repeat wait(1)
		intermissionCountdown.Value = intermissionCountdown.Value - 1
		timer.Text = "Intermission:" ..intermissionCountdown.Value
		until intermissionCountdown.Value <= 0
end

1 answer

instead of doing that. Try a for loop.

local timer = game.StarterGui.Timer.TimerText
local lobbyMusic = game.Workspace.Sounds.Intermission
local inGameMusic = game.Workspace.Sounds.InGame

local storage = game:GetService("ReplicatedStorage")

local intermissionCountdown = storage.Values.IntermissionCounter
local ingameCountdown = storage.Values.InGameCounter
local status = storage.Values.Status

local maps = storage.Maps

if status.Value == "Intermission" then
for i=1, 15, -1 do
task.wait(1)
intermissionCountdown.Value = i
timer.Text = "Intermission: .. i
repeat  wait() until intermissionCountdown.Value <= 0
if intermissionCountdown.Value <= 0 then
break
end
end
end

1 comment

0

Or a while loop checking if the countdown is still over 0

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