Need help scripting a stopwatch

You can write your topic however you want, but you need to answer these questions:

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

  1. What is the issue? Include screenshots / videos if possible!
    Cant make a working stopwatch
  2. 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.

Use this:

local Time =  --change this to your label. 

local Start = tick()

function PlayTimer() 

	while true do

		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

1 Like

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 not give people full scripts? I think its against the rules, also they need to be a bit more independent.

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

Uh…? What.

I don’t know, ive just been told its wrong to give full scripts to people.

Also, ive only been scripting for a month so ofc im not going to know how to fix this.

Sorry for bumping this, but I had the same problem. It was eventually fixed with this post:

Need help, let me know.

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
1 Like