What does it do? How is it different to wait()? How to use it? (Sorry for the long title, the system won't accept it.)
✓ ANSWER ACCEPTED
What/how does delay() mean/it apply in ROBLOX Lua Scripting blah blah blah?
1 answer
✓ Accepted answer
delay only exists in roblox, it's a function that runs given function in another thread after a given time, example like this
local function DoSomething()
print('Hello')
end
delay(10, DoSomething)
This will print "Hello" after 10 seconds, the function itself looks like this
local function delay(Time, Function)
coroutine.wrap(function()
wait(Time)
Function()
end)()
end
You see it does not stop the thread at all, it creates a new coroutine which spawns new thread instantly. Just like wait, Time before executing function must be higher than 1/30, if it's lower, it will automatically be 1/30. In cases where you don't want to stop the thread, you can use delay instead of that.
local Part = Instance.new('Part', workspace)
local Part2 = Instance.new('Part', workspace)
delay(3, function()
Part.Color = Color3.fromHSV(0.5 , 1, 1)
end)
Part2.Color = Color3.new(1, 1, 0)
wait(2)
print(Part2.Color)
print(Part.Color)
wait(2)
print(Part.Color)
> Output:
-- 255, 255, 0
-- 151, 153, 152 (Or whatever the default part color is)
-- 126, 255, 255
Delay is the function at the top here, you can read about it.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Finally it accepted my title ;-;