local seconds = 10
local miliseconds = 99
while wait(0.001) do
if miliseconds > 00 then
miliseconds -= 1
else
seconds -= 1
end
script.Parent.Text = seconds..”.”..miliseconds
end
Sadly wait()cant delay any lower than 0.03 and task.wait() waits 0.016 , so your best choice is task.wait() and adding .016, seconds, wont be a big difference.
You could use tick() or task.wait() in that case because wait() has a delay
local Start = tick()
while task.wait() do
local Diff = tick() - Start
local Min = math.floor(Diff / 60)
local Sec = Diff - Min * 60
local Mil = math.floor((Sec - math.floor(Sec)) * 10)
Sec = math.floor(Sec)
script.Parent.Text = tostring(Sec) .. "." .. tostring(Mil)
end
I think task.wait() would work just fine if they are going for the same result of what the video had ( so for example it would say “3.5 seconds left” )
The short answer is that it’s not possible to get a millisecond countdown. The shortest wait is task.wait which, as others have stated, has a delay of about 0.016 or 16 milliseconds. What you can do is this:
local seconds = 10
while seconds >= 0 do
script.Parent.Text = math.round(seconds * 10) / 10
seconds -= task.wait()
end
EXPLAINATION
The seconds holds the count total wait time. task.wait() returns the actual time it waited, so that value is subtracted from seconds each time the loop iterates. I put the text before the wait because the loop exit condition is that seconds is >= 0. When seconds goes negative, the loop exits. The text line multiplies the seconds by 10, rounds the result, then divides it by 10 to get a 0.1 second countdown. You don’t want to go much more than that because of network latency.
You should generally avoid while loops as much as possible, unless necessary. This would be a better practice as it avoids using spawn function(s), to prevent unnecessary threads that can be avoided, (utilizing my code above).
Now hey, you can do as you please with while loops and I’m not one to judge that, however, this is a better alternative to a while loop to use as a countdown, especially in this situation.