Calling Multiple Functions In A Row [Please Help]

I’m not sure how to explain this well but basically I have a script that has tons of different functions. When function A fires, it is supposed to fire function B, function C, and function D consecutively. The problem is, it fires function B, but then it doesn’t move on until function B “returns”. Now I don’t return function B for like 10 seconds so it doesn’t move on and fire function C until function B is completed. Is there a way to move on before the function returns? Sample code to help explain :

local function B()
	wait(5) --waits(5) then returns
	return
end

local function C()
	wait(3)
	return
end

local function A()
	print("Firing B") --it prints ("B") then 5 seconds later prints ("C")
	B()
	print("Firing C") 
	C()
end
wait(0.3)
A()

Hello! There may be other solutions but I’m pretty sure coroutine can do pretty well in this case!
You can read more about it in this article.

local function B()
	wait(5) --waits(5) then returns
	return
end

local function C()
	wait(3)
	return
end

local function A()
	local Bc = coroutine.wrap(function()
		B()
	end)
	local Cc = coroutine.wrap(function()
		C()
	end)
	
	print("Firing B") -- It'll instanty print B() and C()
	Bc()
	print("Firing C") 
	Cc()
end
wait(0.3)
A()
1 Like

Omg yes that’s right. Thank you so much I never thought of that :slight_smile:!

1 Like