Does this effect the loop?

while true do
print("X")
task.wait(.1)
end

this code ran on client.

does framerate effect how fast the loop goes?

120 framerate > faster loop?

30 framerate > slower loop?

2 Likes

no frame rates don’t affect the loop
however higher frame rates will make the wait time more precise / nearer to 0.1

4 Likes

so ur framerate DOES affect how fast the loop runs

2 Likes

Using task.wait(), ensures consistent timing regardless of the client’s framerate…

3 Likes

No, frame rate only effects loop run speed if it’s using run service.

1 Like

Yes. But not how you imagine


API reference for task.wait:


DevForum release note:


API reference for RunService.Heartbeat


Observed behaviour:
https://gyazo.com/11320f37e1d6b9cc3ce95b2d86c1a61c

2 Likes

thanks for the docs links, I didn’t know who to trust lol

1 Like

@GE_0E was correct. Should you request a specific yield time, task.wait will suspend your thread for that time. Thread resumption is checked every frame. However, once X amount of seconds have elapsed and the thread’s resumption is set for the next frame, the time it takes for your thread to resume is entirely dependent on the time it takes to reach that next frame. This can either cause extended yielding or more precise yielding.

For no set yield time, threads resume as fast as you can generate frames, which is what I am demonstrating in the above reply.

For consistency’s sake, do make use of task.wait’s return value as it acts as a scale factor for calculations that require adjustment for lost or gained frame time

2 Likes

so basically, task.wait ALWAYS waits the amount of time, but when in a loop, whenever it restarts is when it dpeends on time,

so if I waited 1 second in a loop, then the lop restarts, it might not restart instantly?, but still start fast enough there isn’t really a visible difference

1 Like

No. Your loop does not affect task.wait.

task.wait is guaranteed to yield for no less than X seconds, but it will never resume your thread at exactly X seconds. There will always be some additional delay due to the time it takes to reach the next frame/resumption cycle. The slower your frame-rate, the larger the delay. The faster your frame-rate, the smaller the delay. This is what is meant by “precision”.

With the standard frame-rate being 60hz, your delay is roughly 1/60th of a second (0.0166 seconds). So by waiting 1 second, your true yield time is 1.00166 seconds. A one-second frame generation time would make your true yield time 2 seconds.

2 Likes

ok now I do understand how it works