I’m using this script to update a Gui’s text to keep track of how long a server has been up, the problem I’m running into is that minutes can go above 60, so I’ll have a weird clock where it’ll 01:72:49 where 72 is the minutes. I’d rather they reset back to 0 like it does when seconds get above 60 but I’m not sure how to do that.
This does not need any module, ngl, you guys are making it way to hard, I don’t say your doing wrong, but thats a very hard way for doing it
Just do this simple way:
local startingtime = tick()
local function formatnumber(number)
return string.format("%02i",number)
end
while task.wait(1) do
local totaltimetaken = tick() - startingtime
local hours = math.floor(totaltimetaken/3600)
local mins = math.floor(totaltimetaken - (hours*3600))
local seconds = math.round((totaltimetaken - (hours*3600) - (mins*60))/60
Gui.Text = formatnumber(hours)..":"..formatnumber(mins)..":"..formatnumber(seconds)
end
Also @colbert2677 modules shouldn’t be recommended for small stuff like these, this will cause unnesscesary confusion to the OP, and modules should be used for returning exact 1 value
Mostly module scripts are used for large stuff, which prevents RY, Repeating yourself, like you type a code like a function many times, but here, your getting the time time different values, and your only formatting it, you don’t really need to make another module script for a tiny formatting task
btw just formatting the string would be shorter and more readable than using that format function for each number: string.format("%02d:%02d:%02d", hours, minutes, seconds)