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

I'm having trouble making a 5 min, resetting timer. Can you help?

Asked by
epoke466 100
4 years ago

I'm trying to edit a script that creates a 5 minute timer on TextLabel on a SurfaceGui on a part. The edit I'm making to the script is to make the timer reset.

Here is the original script-

01local min = 5
02local sec = 0
03local mic = 0
04 
05while true do
06        mic = mic - 2
07        if mic <= -1 then
08            sec = sec - 1
09            mic = 59
10            if sec == -1 then
11                min = min - 1
12                sec = 59
13                if min == -1 then
14                    min = 0
15                    sec = 0
View all 38 lines...

Here Is the edited script-

01local min = 5
02local sec = 0
03local mic = 0
04 
05while true do
06    while true do
07        mic = mic - 2
08        if mic <= -1 then
09            sec = sec - 1
10            mic = 59
11            if sec == -1 then
12                min = min - 1
13                sec = 59
14                if min == -1 then
15                    min = 0
View all 40 lines...

I assumed that adding an extra-

1while true do
2 jsdnjdnajbfhbhjfbahbfhbf
3end

I could make the timer repeat but it's not working, can you please help me

1 answer

Log in to vote
0
Answered by 4 years ago

Fixing your script seemed very tedious, here's a version that should suit you much better. The function does all the heavy lifting of converting the time into an appropriate string, and the while loop will adjust the text.

01local timer = 300 -- seconds
02 
03function clockConversion(seconds)
04    if seconds <= 0 then
05        return "00:00"
06    else
07        mins = string.format(".f", math.floor(seconds/60))
08        secs = string.format(".f", math.floor(seconds - (mins *60)))
09        return mins..":"..secs
10    end
11end
12 
13while wait(1) do
14    script.Parent.Text = clockConversion(timer)
15    timer -= 1
16end
0
Thanks epoke466 100 — 4y
Ad

Answer this question