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

how can i fix my intermission countdown its stuck?

Asked by 4 years ago

i was making a countdown for my intermission and its stuck at 14

local MapsFolder = game.ReplicatedStorage:WaitForChild("Maps") local Status = game.ReplicatedStorage:WaitForChild("Status")

while true do Status.Value = "Intermission 15" local interTime = 15 repeat wait() wait(1) interTime = interTime - 1 Status.Value = "Intermission "..interTime until interTime <= 0 wait (2) end

1
CODE BLOCK ACHRONlX 255 — 4y
1
please use a code block, so we can read the code properly Dec_ade 47 — 4y

4 answers

Log in to vote
0
Answered by
ACHRONlX 255 Moderation Voter
4 years ago

Put the Status.Value = "Intermission 15" and local Intertime = 15 outside of the forloop and you should be good.

0
I mean the while - do loop, my bad. ACHRONlX 255 — 4y
0
That has nothing to do with the problem. That'll change nothing. DevingDev 346 — 4y
0
I recommend using a for loop instead of a while loop for timers. Dovydas1118 1495 — 4y
Ad
Log in to vote
0
Answered by
Dec_ade 47
4 years ago
Edited 4 years ago
1while true do
2wait(1)
3Status.Value = "Intermission" ..interTime
4    if interTime ~= 0 then
5        interTime = interTime - 1
6   end
7else
8      break;
9end
Log in to vote
0
Answered by
DevingDev 346 Moderation Voter
4 years ago
01local MapsFolder = game.ReplicatedStorage:WaitForChild("Maps")
02local Status = game.ReplicatedStorage:WaitForChild("Status")
03 
04local intermissionTime = 15
05local startTime
06 
07while true do
08    startTime = tick()
09    Status.Value = "Intermission 15"
10    repeat     
11        local timeSinceStart = math.floor(tick() - startTime)
12        Status.Value = "Intermission " .. intermissionTime - timeSinceStart
13 
14        wait(1)
15    until intermissionTime - timeSinceStart <= 0
16 
17    wait(2)
18end
Log in to vote
0
Answered by 4 years ago

for timers/countdowns, I do not recommend using a while loop. Use a for loop instead. I'm assuming your status is a string value.

1local status = game:GetService("ReplicatedStorage"):WaitForChild("Status")
2local Timer = 15
3for i = Timer, 1, -1 do --This just countdowns down by 1 second
4    print(i)
5    Status.Value = "Intermission: "..i.." seconds left"
6    wait(1)
7end

If you want it to keep going on forever, then put a while wait() do at the top. (You can use a while true do, however, it may crash your script or studio.)

Answer this question