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

01local startmin = 0
02local startsec = 0
03local text = script.Parent
04local min = 0
05local sec = 0
06 
07while true do
08    startsec = startsec + 1
09    print("Added 1 sec")
10    if startsec == 60 then
11        startsec = 0
12        startmin = 1
13    end
14    if sec > 9 then
15        local mess = "0" .. startmin .. ":" .. startsec
View all 22 lines...
0
short answer: no it does not print 00:010. Elixcore 1337 — 5y
0
utilize string formatting DeceptiveCaster 3761 — 5y

1 answer

Log in to vote
0
Answered by 5 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