Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

2 comments

0

short answer: no it does not print 00:010.

0

utilize string formatting

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.