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

Why does it do this?

local TimeLimit = 360

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

When the time turns at 5:09 it turns to a 5:9 instead of 5:09 as i want it to!

Help!?

1 answer

string.format

When you hit 09, Lua doesn't see the leading 0s and just turns it into 9 as a string. The solution is to look into string formatting to make sure that it knows you want the leading 0s.

string.format(
	'Time: %.1d:%.2d', -- % means it's a new symbol, .1/.2 is how many places (As a minimum), d means a number (With no decimal places)
	time/60, -- Our minutes
	time%60 -- Our seconds
) --> 5:09

6 comments

0

I still kinda don't get it. Since i got the time script from my friend...

0

Well that's no use then. I can't help you if you don't understand your original script.

0

I do understand that, But i dont understand string.formant and what you did..

0

Did you look on the page I linked, and read my comments? %.1d literally means a number to 1 place, and %.2d means the same to 2 places. I can't explain it any better than I already have.

0

Oh i didnt see that part ops

0

"oops."

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