Whats the difference from task.delay and task.wait()?
Essentially task.delay()
is for delaying a specific function or a thread. Hence having both a time and function input. Similar to task.wait()
in regards that no throttling will occur when you are delaying something and will resume on the next heartbeat after the provided second(s).
task.wait()
is very similar to wait()
but no throttling will occur with this and will continue on the next heartbeat after the amount of time in second(s).
With both of these, if no time value is provided it will default to 0
which will guarantee that the thread will continue on the next heartbeat. As said inside of the documentation you can check the actual time it takes with os.time
The primary difference is that task.wait()
yields the current thread of execution (the ‘thing’ that is handling code execution) whereas task.delay()
creates an alternative thread and yields the execution of that instead.
print("Hello world!")
task.wait(1) --Current thread is yielded for one second.
print("Hello world!") --This print occurs after one second.
print("Hello world!")
task.delay(1, function() end) --Creates an alternative thread of execution and runs a function after one second.
print("Hello world!") --This print occurs immediately upon script execution.