Delay is very useful and simply delays a function by X seconds without yielding your script.
So, what does this mean? What do the terms function and yield mean?
A function is basically a Block or Chunk of code.. several lines if you will that can normally be "used" several times.
Yielding can be described as pausing, in our case, delay sort of "yields" the function you provided by the amount of time you gave.
These are simple definitions however, not exactly accurate but may help you understand more.
delay(3, function()
print("Hello")
print("World")
end)
print("!")
The above will print "! Hello World" in your output instead of the ! being last like the prints are written, the first two prints are delayed by 3 seconds which cause ! to be printed first, showing you delayed your code by 3 seconds WITHOUT stopping the code. If you were to use a wait(3) without delay, nothing in your script would progress until those 3 seconds are complete.
The lua thread is a bit complicated, but for now I suggest thinking of it as a service running all your scripts. If you use delay, you create a thread that is delayed while your current thread (the script being used) still continues. If I have confused you, please feel free to comment below any question!
2 comments
Yield meaning makes me confused too ;-;
Im actually working on a project using these things, and I;m still new to them too