for some reason task.wait(1) waits less than a second, or time() is weird
I’m trying to check if time() - lastTimeRn >= 3.9 which in theory should work
this is my script
lastTimeRan = time()
task.wait(1)
print(time() - lastTimeRan)
task.wait(1)
print(time() - lastTimeRan)
task.wait(1)
print(time() - lastTimeRan)
task.wait(1)
print(time() - lastTimeRan)
if time() - lastTimeRan >= 3.9 then
print("yes3")
end
but instead i usually get this in the output:
and so the conditional doesn’t happen
I have no clue why this is happening
Oh. Sorry about that. My mistake, lol.
If you look, I am not a professional at scripting. My guess is just to perfectly re-do it or maybe get help from a scripting supporter.
I noticed that the script actually works as intended after about 10 seconds of the server/game existing.
there is nothing interfering with lastTimeRan other than that
Is the code running multiple times, at the same time?
If so, it’ll set the variable, and start waiting
If it runs again and the variable is set, when the first wait finishes, it’ll use the new variable.
os.clock is accurate, both in Studio and in-game. It measures CPU time, intended for benchmarking, and will work both in Studio and in-game (client and server). It should be noted that there will be a lag spike when a server starts, as well as on the client when the player first joins, and potentially with any future lag spikes due to poor performance.
task.wait is accurate at least to the first decimal (10th of a second), and will only be seen at most 1.01 seconds in normal conditions. The accuracy will vary with things such as performance and frames. Heartbeat is calculated at the FPS level, after physics calculations (Stepped occurs before). The higher the framerate, the better the accuracy.
In short, task.wait is accurate enough for almost every scenario.
Also, even with lag spikes, task.wait does appear to remain accurate for the most part (especially if the waiting period is longer).