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

Why does it change like this?

for i = 120, 0, -1 do
Time = "Time: " .. tostring(math.floor(i / 60)) .. ":" .. tostring(i % 60)
G_MSG.Value = Time
wait(1)
end

I'm going to ask once again, And i don't understand why but i need more information. So when the timer goes down to about 1:09 it goes 1:9 instead to 1:09 as i want it to be. And i searched on this wiki about string and i still dont get it. Help.

1 comment

0

It does this because the numerical representation of a mathematical equation is the number itself. 0 is merely a visual placeholder we have put into effect.

2 answers

✓ Accepted answer

9%60 is 9. Numbers don't arbitrarily come with a zero in front of them for no reason, so you need to put it there if you want it to be there. An easy solution to this is to write ('0'..(i%60)):sub(-2) to get only the last two digits, so the string would be

Time = "Time: " .. math.floor(i/60) .. ":" .. ("0"..(i % 60)):sub(-2)

A work-around for this:

for i = 120, 0, -1 do

local timeString = i%60

if timeString < 10 then
	timeString = "0"..timeString
else
	timeString = tostring(timeString)
end

Time = "Time: " .. tostring(math.floor(i / 60)) .. ":" .. timeString

G_MSG.Value = Time
wait(1)
end

1 comment

1

Great explanation

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