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

Stopwatch seconds kinda breaks when it reaches 10. Any help?

Asked by 4 years ago

I've been trying to make a stopwatch for an obby game of mine, which times you as you complete it. When the stopwatch reaches 10 however, it breaks and say "00:010" instead of "00:10" like its suppose to. If anyone could help, that would be great.

Its inside a local script with its parent being a textlabel.

local startmin = 0
local startsec = 0
local text = script.Parent
local min = 0
local sec = 0

while true do
    startsec = startsec + 1
    print("Added 1 sec")
    if startsec == 60 then
        startsec = 0
        startmin = 1
    end
    if sec > 9 then
        local mess = "0" .. startmin .. ":" .. startsec
        text.Text = mess
    else
        local mess = "0" .. startmin .. ":0" .. startsec
        text.Text = mess
    end
    wait(1)
end

0
short answer: no it does not print 00:010. Elixcore 1337 — 4y
0
utilize string formatting DeceptiveCaster 3761 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Because you are not changing the variable 'sec' anywhere in your script, so it always shows a 0 before each number. make sure after every second in your while loop, you put sec=sec+1. Also ensure that startmin when you are using it is startmin+1 where you have put in the while loop, otherwise is will always show startmin's value as 1.

Ad

Answer this question