put this under a local script inside of a textlabel:
local milisecond = 0
local second = 0
local minute = 0
local hour = 0
while wait(0.01) do
if milisecond >= 60 then
milisecond -= 60
second += 1
end
if second >= 60 then
second -= 60
minute += 1
end
if minute >= 60 then
minute -= 60
hour += 1
end
milisecond += 1
script.Parent.Text = hour..":"..minute..":"..second.."."..milisecond
end
I would recommend against this method, as using wait(0.01) could cause problems. wait() is known to have problems with it not correctly waiting for the small amount of time like 0.01. I suggest you re-implement this solution with something like tick().
Well how many players did you have in your testing? How many things were going on? I’m saying that I myself have had problems using wait(), and I am simply suggesting that tick() is a safer solution that can have more decimal places if ever necessary in the future, and it’s usage is actually meant to count time in seconds.
even so, its local so it wouldnt cause any lag as it doesnt run other peoples timer. It does not have any problems at all, I get that in different ways tick() can be better but for this its perfectly fine and as for “wait having problems with small numbers” it with something like this. It only has problems with small numbers if you’re having a lot of things running from it within that short time.
The point is, doing wait() manually worse than using tick(), os.time(), or another similar method that’s meant to be used for that, as well as accurately counts the time - free of lag or most problems you could encounter with wait().
Also, it’s not actually waiting for 0.01 seconds to let you know. The fastest you can do with wait() is 0.03, no lower. So it’s not working correctly. I recommend you switch it to an os.time or tick() method instead.
So, if I were to add to add an if statement to the script it doesn’t work. I stated if player.Started.Value == true then the timer would start but it didn’t.
No it does not. You’re not aware that it’s only running at 0.03 seconds, not 0.01? The limitation of wait() is 0.03, which is about 1/30th of a second.
here is a script that will run in the way you wanted it to. It will only give the time if they have started.
local milisecond = 0
local second = 0
local minute = 0
local hour = 0
while wait(0.01) do
if milisecond >= 60 then
milisecond -= 60
second += 1
end
if second >= 60 then
second -= 60
minute += 1
end
if minute >= 60 then
minute -= 60
hour += 1
end
if game.Players.LocalPlayer.Started.Value == true then
milisecond += 1
end
script.Parent.Text = hour..":"..minute..":"..second.."."..milisecond
end
So even though you are defining wait(0.01) its not gonna work at all because the wait() can only go to 0.03 so your script is not gonna work as intended because its gonna run .02 seconds slower than it is meant to. The script may still work because Lua is a forgiving language but your time will always be off. I believe if you change wait to tick() it should fix that problem because the tick() function allows you to start from 0.01.