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

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

Asked by 2 years ago

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

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

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
0
Or a while loop checking if the countdown is still over 0 Antelear 185 — 2y
Ad

Answer this question