How to make a function inside a function not wait for the one in it to finish?

So basically i got a quick question about functions!

Is there any way to not make a function wait for another one called inside of it?
Here is a little example:

function countDown()
	for i = 1,10 do
		print("Ok"..i)
		wait(1)
	end
end


function testPrinting()
	print("Hello")
	countDown()
	-- while the countDown function is running do something else
	-- for example 
	for i = 1, 10 do
		print("Test"..i)
	end
end

testPrinting()


end

So the question is how do i make the testPrinting function not wait until the countDown function is done? So it ignores anything that is happening with that function?

Thanks for the help!

Make use of the task.spawn function.

Example:

local function countDown()
    for i = 10, 0, -1 do
        print("Test:", i)
        task.wait(1)
    end
end

local function anotherFunction()
    print("Running")
    task.spawn(countDown)
    
    -- do other stuff also like
    for i = 1, 10 do
        print("Counting up:", i)
        task.wait(1/10)
    end
end

anotherFunction()
1 Like