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.
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.
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)