I’m currently trying to make a timer system but I need it to wait exactly 1 second, how would I do this? Considering wait()
is inconsistent what would be more reliable.
You can’t. If you want to make a timer set a start time and calculate the time passed:
local start = os.clock() -- when it starts counting
while wait() do
print(os.clock() - start) --> prints how much time has passed
end
Alternatively, you can round down so it displays in seconds:
local start = os.clock() -- when it starts counting
while wait() do
print(mat.floor(os.clock() - start)) --> prints how much time has passed rounded down
end
1 Like
Theres no possible method to get to 1 second. You should use task.wait(1)
or the os.clock methods others mentioned then, but task.wait its a more reliable wait() method, and is really close to 1 second, but this is the easiest way to do it
Here is a accurate timer, down to 100 nanosecond precision on my PC.
function waitAccurate(ts)
local t = os.clock()
while os.clock()-t < ts do
end
end
4 Likes
For example, here is the real time when I waited for 1 second with this code:
real time: 1.0000006000045687
1 Like