Help with my timer

So I made a timer GUI, and it’s doing this for some reason.

Here’s the code if anyone needs it to debug.

module.Timer = function(Time, Screen)
	local Timer = game:GetService("RunService").Heartbeat

	Timer:Connect(function()
		local Remaining = Time - tick()

		local Minutes = math.floor(Remaining / 60)
		local Seconds = math.floor(Remaining % 60)
		local Milliseconds = math.floor((Remaining * 1000) % 1000)
		local TimerText = string.format("[%02d:%02d:%02d]", Minutes, Seconds, Milliseconds)
		
		ScreenFolder[Screen].Main.SurfaceGui.Timer.Timer.Text = TimerText
	end)
end

Did you make sure to give the you want alloted + os.time()? Because tick goes off of unix.

I didn’t really understand you, mind rewording it?

tick() returns the amount of time has passed since the unix epoch.
I’m assuming what’s happening is that you are giving some amount of time in seconds that you want the timer to run for (for example 120 for 2 minutes), and that’s what the timer is using for it’s math.
So you are doing 120 - 1.6 Billion something seconds.
You should add os.time() or tick() to the time before you start the heartbeat.

local Timer = game:GetService("RunService").Heartbeat
 -- Time += tick()
	Timer:Connect(function()
...
end)
1 Like

The other reply should be the solution to this, but I also wanted to mention that tick() is technically deprecated now, so you should use either os.clock() or os.time() in its place

Mmm. Have you checked out the DateTime data type?

It’s got a really nice method fromUnixTimestamp which takes in a value returned by tick() or os.time() and gives you a DateTime object that can be formatted in a lot of ways.

This worked, however the minutes are counting down like normal seconds for some odd reason, and seconds are milliseconds.