So I was just scripting functions for fun and then I found one function that caught my eye. It was named “delay”, and I didn’t know how to use the function. I tried searching the web but there were no descriptions to fix the problem. So I’ve decided to ask you guys for help about this.
delay(time, func) makes a new thread in a manner most similar to spawn and runs that thread after time seconds. You can find more information about globals on the wiki.
delay is used for, as the name implies, to delay the call of the function provided given for the given amount of seconds, without interrupting the current thread.
This will print "Hello!" first, since the first function is called in a separate thread after roughly five seconds. delay also passes the actual time waited, similar to spawn and wait
local time = 1
local repeats = 5
local start
for i = 1, repeats do
start = tick()
delay(time, function()
print(tick() - start)
end)
wait(time)
print(tick() - start)
end
The global function delay takes 2 arguments: first is a time to wait in seconds, the second is the function to call after the wait time has elapsed, delay continues executing unlike wait which blocks.
local function Test()
print'This is actually cool!'
end;
delay(3, Test);
print'This ran first!'