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