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
3 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-

local min = 5
local sec = 0 
local mic = 0 

while true do
        mic = mic - 2
        if mic <= -1 then
            sec = sec - 1
            mic = 59
            if sec == -1 then
                min = min - 1
                sec = 59
                if min == -1 then
                    min = 0
                    sec = 0
                    mic = 0
                end
            end
        end
        if min <= 9 and sec <= 9 and mic <= 9 then
            script.Parent.Text = "0" ..min.. ":0" ..sec..":0" ..mic
        elseif min <= 9 and sec <= 9 and mic >= 10 then
            script.Parent.Text = "0" ..min.. ":0" ..sec..":" ..mic
        elseif min <= 9 and sec >= 10 and mic <= 9 then
            script.Parent.Text = "0" ..min.. ":" ..sec..":0" ..mic
        elseif min <= 9 and sec >= 10 and mic >= 10 then
            script.Parent.Text = "0" ..min.. ":" ..sec..":" ..mic
        elseif min >= 10 and sec <= 9 and mic <= 9 then
            script.Parent.Text = min.. ":0" ..sec..":0" ..mic
        elseif min >= 10 and sec <= 9 and mic >= 10 then
            script.Parent.Text = min.. ":0" ..sec..":" ..mic
        elseif min >= 10 and sec >= 10 and mic <= 9 then
            script.Parent.Text = min.. ":" ..sec..":0" ..mic
        elseif min >= 10 and sec >= 10 and mic >= 10 then
            script.Parent.Text = min.. ":" ..sec..":" ..mic
        end
        wait()
    end

Here Is the edited script-


local min = 5 local sec = 0 local mic = 0 while true do while true do mic = mic - 2 if mic <= -1 then sec = sec - 1 mic = 59 if sec == -1 then min = min - 1 sec = 59 if min == -1 then min = 0 sec = 0 mic = 0 end end end if min <= 9 and sec <= 9 and mic <= 9 then script.Parent.Text = "0" ..min.. ":0" ..sec..":0" ..mic elseif min <= 9 and sec <= 9 and mic >= 10 then script.Parent.Text = "0" ..min.. ":0" ..sec..":" ..mic elseif min <= 9 and sec >= 10 and mic <= 9 then script.Parent.Text = "0" ..min.. ":" ..sec..":0" ..mic elseif min <= 9 and sec >= 10 and mic >= 10 then script.Parent.Text = "0" ..min.. ":" ..sec..":" ..mic elseif min >= 10 and sec <= 9 and mic <= 9 then script.Parent.Text = min.. ":0" ..sec..":0" ..mic elseif min >= 10 and sec <= 9 and mic >= 10 then script.Parent.Text = min.. ":0" ..sec..":" ..mic elseif min >= 10 and sec >= 10 and mic <= 9 then script.Parent.Text = min.. ":" ..sec..":0" ..mic elseif min >= 10 and sec >= 10 and mic >= 10 then script.Parent.Text = min.. ":" ..sec..":" ..mic end wait() end end

I assumed that adding an extra-

while true do
 jsdnjdnajbfhbhjfbahbfhbf
end

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 3 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.

local timer = 300 -- seconds

function clockConversion(seconds)
    if seconds <= 0 then
        return "00:00"
    else
        mins = string.format(".f", math.floor(seconds/60))
        secs = string.format(".f", math.floor(seconds - (mins *60)))
        return mins..":"..secs
    end
end

while wait(1) do
    script.Parent.Text = clockConversion(timer)
    timer -= 1
end
0
Thanks epoke466 100 — 3y
Ad

Answer this question