Right now Im trying to make a stopwatch thing that includes milliseconds which is where I have a problem. The milliseconds is not working the way I want it to and I can’t think of the solution.
this is what I want it to do
but right now its doing
This is my script right now
local function ToMS(s)
for i = 1,270 do
Some help would be appreciated
I’ve found so much trouble trying to explain why this isn’t working and it’s because the way each item is interacting with each other is fundamentally weird. I can’t find the right words to articulate it. Took me a solid few minutes of testing and rewriting to figure out how to say this and it’s still weird.
You’re counting 270 seconds across 27 seconds. The for loop counts integers from 1 to 270, there’s no room for partial seconds but you make up for that by changing the wait time instead. But then your ToMS function treats the input as seconds. The milliseconds format is actually just the same thing as the seconds one but instead of resetting at 60, it resets at 10 - these aren’t actual milliseconds.
Instead of trying to figure out this weird math, I just wrote a new one that works based off of Heartbeat frequency. Much easier to do and it provides more accurate timing than wait. Heartbeat provides partial seconds as the measure is the time between two frames executing.
local RunService = game:GetService("RunService")
local Heartbeat = RunService.Heartbeat
local FORMAT = "%d:%.2d.%d"
local function getTimeFormat(aggregate)
local milliseconds = math.floor(aggregate*10)%10
local seconds = math.floor(aggregate)
local minutes = math.floor(seconds/60)
print(FORMAT:format(minutes, seconds, milliseconds))
local agg = 0
for i = 0, 1000 do
agg = agg + Heartbeat:Wait()
For loop is only for testing, I hope you don’t actually use that in production code. Time should be held in a different way if at all possible, such as a while loop counting down an arbitrary timer.