Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to create a milliseconds timer without it skipping 0.1 second sometimes?

Asked by 3 years ago

I am trying to make a milliseconds timer using localscript, but it seems to be skipping 0.1 second sometimes.

Here is my script:

wait(1)
local StartTick = tick()

while true do
    local Second = tick() - StartTick
    Second = Second * 10
    print("original second: "..Second)
    Second = math.floor(Second)
    Second = Second / 10
    script.Parent.Timer.TextLabel.Text = Second
    print("fixed second: "..Second)
    wait(0.1)
end

I put print for original second and fixed second, here's the output: https://i.gyazo.com/afe8fc2411ea85a8f473dac7c7a4c6a0.png

1 answer

Log in to vote
0
Answered by 3 years ago

problem: you're doing it in a while do loop, which means it's not recommended to remove wait(0.1) but the problems of skipping is in the wait() at the bottom of your loop. try changing it to wait() or RunService.Heartbeat:Wait()

Ad

Answer this question