Task.wait() is interfering with another Task.Wait()?

I was making endlessly moving background objects with two parts, and I had two task.waits in my while true loop, which for some reason broke the timings of the moving parts.

I originally had one of the task.waits as just a wait()


and it was perfectly fine

but when I made it a task.wait it just broke


I solved it by removing the first task.wait(), but I was just wondering what the reason for this happening is.

1 Like

wait and task.wait probably behave slightly different. wait was created first and was probably kept for compatability in old scripts. I don’t know what the exact differences are.

task.wait is a newer version of wait
It was added along other stuff in task library
Task.wait uses new task scheduler for yeilding thread.
Task.wait should be a bit faster than wait and should probably be even more accurate for people that have FPS unlock

Also tip for the future…Put yeilding at the end of task please

I imagine the problem is something along the lines of that your code is expecting a certain wait time based on how long the “playTrackTween” function takes. If this is the case it would probably break in edge cases anyways.

If you’re waiting based on a tween you should probably wait on the tween itself (ex: tween.Completed:Wait()).


One possible reason for the difference is that wait(1.15) doesn’t wait for the next heartbeat and task.wait() does; but task.wait(1.15) finishes after a heartbeat then task.wait() has to wait for the following heartbeat.

You could just remove the task.wait() at the top because your other code will always yield.


If you show the playTrackTween function and/or explain what’s going wrong we could get a better idea of how to fix it.