I’m making a timer with minutes in it, however it would look and count like this normally:
NOTE: The example timers in this post are 5 minutes (300 seconds), just incase you need to know that.
300, 299, 298, you name it.
I want to format it to make it look and count like this:
5:00, 4:59, 4:58, you name it.
Anyone know? It probably involves something with string.sub but I don’t know exactly what it is.
If you know, please let me know in a reply to this post.
local totalSeconds = 300
while totalSeconds > 0 do
local minutes = math.floor(totalSeconds/60)
local seconds = totalSeconds - minutes*60
local timeString = minutes .. ":" .. seconds
totalSeconds -= 1
wait(1)
end
local function formatTime(seconds)
local min = math.floor(seconds / 60)
local sec = seconds % 60
return string.format("%i:%02i", min, sec)
end
print(formatTime(283)) -- 4:43