Problems With Time Elapsed Script

Hello! I was making a time elapsed display for a game, but I came across an error: When the minutes passed 60, it kept going past 60 (i.e. 61, 62, 82, 192, etc.). The hour indicator increases accordingly, but the minute indicator allows itself to go over.

Here is the script I am having troubles with:

local initTime = tick()
local mula = game.Players.LocalPlayer.leaderstats.Cash.Value

while wait(1) do
	local profit = game.Players.LocalPlayer.leaderstats.Cash.Value - mula
	local timeElap = tick() - initTime
	local hour = math.floor(timeElap / 60 / 60)
	local min = math.floor(timeElap / 60)
	local sec = timeElap - min*60
	sec = math.floor(sec)
	
	amount1.Text = hour..":"..min..":"..sec
	amount2.Text = "$"..profit
end

Thanks,

  • Ham

Here’s a bit of a rewrite inside of your code:

local s = math.floor(timeElap)
local m = math.floor(s/60)
s %= 60
local h = math.floor(m/60)
m %= 60

1 Like

Alright, thanks! I’ll mark this as the solution after an hour lol.