Does client's lag affect task.wait()?

I was just wondering, does client’s lag affect task.wait()? Like if the code would be task.wait(5) the client’s screen would freeze for like 10 seconds due to low FPS, will that task.wait(5) line run after the lag has ended or when the client is lagging?

Code after the task.wait() will run after the time has elasped and when it’s able to.

If the user is was frozen, the CPU was overloaded, and the code after task.wait() has no opportunity to run, thereby the code after task.wait() is impacted by lag.

You can think of it this way. task.wait() waits a minimum of a single frame, and if the frame takes 10 seconds, task.wait() will also take 10 seconds.

Observe the output of this code:

local running = true
task.spawn(function()
    while running do
        print("running")
        task.wait()
    end
end)

task.wait(0.5)

local t1 = os.clock()
repeat --> artificial lag
until os.clock() - t1 >= 1

task.wait(0.5)

running = false
3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.