You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want to make a fully working stopwatch with includes minutes, seconds and miliseconds. And the parent of the localscript is a textlabel, where it shows the time.
What is the issue? Include screenshots / videos if possible!
Cant make a working stopwatch
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Searched out on youtube, devforum and it did not worked.
local Time = --change this to your label.
local Start = tick()
function PlayTimer()
while true do
wait()
local Difference = tick() - Start
local Minutes = math.floor(Difference / 60)
local Seconds = Difference - Minutes * 60
local Milliseconds = math.floor((Seconds - math.floor(Seconds)) * 10)
Seconds = math.floor(Seconds)
if string.len(Milliseconds) < 3 then Milliseconds = "0" .. Milliseconds end
if string.len(Seconds) < 2 then Seconds = "0" .. Seconds end
if string.len(Minutes) < 2 then Minutes = "0" .. Minutes end
local Format = Minutes .. ":" .. Seconds .. ":" .. Milliseconds
Time.Text = Format
end
end
PlayTimer()
But one problem. There is a 0 added infront of the millisecond. ex: 13:01 it should be 13:10. Kind of hard to explain but if you test it you will know I think.
Can you explain what it does rather than spoonfeeding him?
To OP:
What have you tried so far specifically, “search out on youtube, devforum” isn’t going to help? What and how it doesn’t work? “it did not work” is vague and doesn’t help along with “Can’t make a working stopwatch”.
I apologize for bumping this but I found this very helpful when searching for how to make a stopwatch, but also wanted to share the solution for it adding a zero to the milliseconds where it shouldn’t.
The Milliseconds need to be multiplied by 1000, not 10 if you want to display 3 digits of the milliseconds. And then if the adding zero conditional there needs to be a check for <2 and <3 like this:
local Milliseconds = math.floor((Seconds + 0.0005 - math.floor(Seconds + 0.0005)) * 1000)
if string.len(Milliseconds) < 2 then
Milliseconds = "00" .. Milliseconds
elseif string.len(Milliseconds) < 3 then
Milliseconds = "0" .. Milliseconds
end