I want to make a function that doesn’t interrupt the script.
local function Example()
wait(3)
print("A")
end
wait(2)
Example()
wait(3)
print("B")
I want the script to print A and B at the same time. But instead, it would print A, then print B 3 seconds later.
What I want to happen:
waits 5 seconds, prints both A and B
What happens:
waits 5 seconds, prints A, waits 3 seconds, prints B
How would I do this with functions?
1 Like
BirdieI90
(Ping)
#2
use coroutine so it wont yield
local function Example()
task.wait(3)
print("A")
end
coroutine.wrap(Example)()
task.wait(3)
print("B")
5 Likes
Katrist
(Katrist)
#3
Try this:
local function Example()
task.wait(3)
print("A")
end
task.wait(5)
task.spawn(Example)
print("B")
3 Likes
Korabi20
(Korabi_Dev)
#4
You have 2 options here.
- Using a thread such as task.spawn that @Katrist mentioned (do not use coroutine here like @BirdieI90 mentioned)
- Using task.delay like the following example.
task.delay(3, function()
print("A")
end)
task.wait(3)
print("B")
Hope it helps.
1 Like
system
(system)
Closed
#5
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.