-
What do you want to achieve?
Hello, so i want to make a timer with minutes, seconds, and milliseconds.
Something like that : 12:25:54 (MM:SS:MS) (It’s a countdown) -
What is the issue?
I want to make the script efficient, but i don’t know how. -
What solutions have you tried so far?
I looked on devforum and i didn’t find.
Figured out how to make H:M:S, which is not exactly what you want.
But I don’t have much time to correct this now, so hopefully you can modify this code to fit for your needs.
function Convert(n)
local hours = (n / 60 / 60)
local minutes = (n / 60 % 60);
local seconds = (n % 60);
return string.format("%0.2i:%0.2i:%0.2i", hours, minutes, seconds)
end;
print(Convert(50))
print(Convert(90))
print(Convert(60*60))
--[[ Output:
00:00:50
00:01:30
01:00:00
--]]
Here is a function:
function secsToMinsSecsMills(secs)
local mins = math.floor(secs/60)
local secsLeft = secs % 60
local secsGood = math.floor(secs)
local mills = math.floor((secs-secsGood) * 1000)
return mins .. ":"..secsGood..":"..mills
end
Mistake made, here is fixed function:
function secsToMinsSecsMills(secs)
local mins = math.floor(secs/60)
local secsLeft = secs % 60
local secsGood = math.floor(secsLeft)
local mills = math.floor((secsLeft-secsGood) * 1000)
return mins .. ":"..secsGood..":"..mills
end
In both cases you’d just end up with a number ending in 3 zeros (which would essentially mean the timer is in seconds not milliseconds).
DateTime.now() is what you need for precision of time down to the millisecond.
All the function does is turn a time in seconds and milliseconds then makes it into the format mins:seconds:mils as the OP requested. os.clock() would be better as it’s the most accurate timer in roblox down to the microsecond, ive even seen it go down to 100 nanosecond precision.
Yeah but the OP wanted that accuracy.