Creating a timer that displays milliseconds

Hello. I am trying to make a timer like this one:

How can I do that? I just need 00:00:00 (minutes, seconds and milliseconds), and I’ve tried while loops and for loops but they do not work, since they do not work fast enough, and the timer lags behind. Any help is appreciated. Thanks!

Just a suggestion based on an issue in that video. When you make yours, it will look better if the text is either left justified or (preferably) you use a monospace font for it.

1 Like

This seems promising, but I have no idea what you are talking about. Could you please elaborate? Thanks

So how would I used DeltaTime to make the timer? Sorry for being slow, I am just not very sure how to do this.

someone had a similar question (if not identical) and had it solved i suggest looking for it

maybe a few weeks ago

Please mark your last post as the solution, but add the link to the post that fixed it.
This will keep people from trying to answer it over and over, and will link others looking for a solution to the post you mentioned.

1 Like

Displaying milliseconds for a timer is better done using benchmarking, as using the delta value from either RenderStepped or Heartbeat won’t guarantee you an accurate timer.
By benchmarking, i mean using the os.clock() method to store when the timer has started and calculate how much time has elapsed since the timer started.
os.clock() is accurate in milliseconds, as this uses the CPU timer to determine their outputs.
The function itself just returns how long has roblox been running in seconds.
As for displaying minutes, seconds and milliseconds, this requires using the modulus operator (%), divisions and string manipulations.
In the timer you’re showing, i assume it’s a countdown timer, so i’ll be giving an example to how i would write it off:

local deadline = os.clock() + 180 -- 3 Minutes
local timerFormat = "%d:%d.%d" -- As long it has the "%d", it will be possible to replace them with numbers.

function UpdateTimer() -- Assuming this is inside of a BindToRenderStep or Updater.
   local remaining = deadline - os.clock()
   local m = math.floor(remaining/60) -- Minutes
   local s = math.floor(remaining%60) -- Seconds
   local ms = math.floor((remaining%1)*1000) -- Milliseconds

   TimerLabel.Text = string.format(timerFormat,m,s,ms) --> 2:59.960
end

RunService.Heartbeat:Connect(function()
   -- . . .
   UpdateTimer()
   -- . . .
end)
5 Likes

Thank you so much! Spent a long time trying to find a solution.

1 Like

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