(REPOST) How do I make a timer with deciseconds?

So I am trying to make a timer that formats something like this: [ min:s:ds ] but I am not sure how. I already have a script from the devforums:

local textObject: any = script.Parent
local MAX_TIME_DEFAULT: number = script.Parent.TotalTime.Value
local timeRemaining: number = MAX_TIME_DEFAULT
local rate: number = 1 -- 1 times a second
local accumulated: number = 0

game:GetService("RunService").Heartbeat:Connect(function(deltaTime: number)
	accumulated += deltaTime
	while accumulated >= rate do
		accumulated -= rate

		if timeRemaining > -1 then
			local seconds = timeRemaining % 60
			local formatString = '[ %d:%d ]'
			if seconds < 10 then
				formatString = '[ %d:0%d ]'
			end
			textObject.Text = string.format(
				formatString,
				math.floor(timeRemaining * .0166666667),
				seconds
			)
		end
		timeRemaining -= 1
	end
end)

but idk how to modify it to have deciseconds…

2 Likes

Change rate to 10. deci-seconds are now calculated as timeRemaining % 10, and seconds are (timeRemaining / 10) % 60

1 Like

Sorry, rate should be 0.1 not 10. The comment is misleading.

I’ll try it then, sorry it took me long I was sleeping

Seconds are broken. They countdown from 10 for some reason…

1 Like

Ok so. I had to multiply timeRemaining by 10 and format the minutes like this:

math.floor((timeRemaining / 10) * .0166666667)

and the script worked just fine.

1 Like

Is there a reason you are multiplying by 0.016 instead of dividing by 60?

1 Like

Uhh yeah… Don’t ask me. I just copyed the script without knowing what it meant but now I know what it means so yeah

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.