Problem with functions

Hi there,
I’ve encountered an issue with functions.


So here I have this code:

local function Function1()
   print("Pizza")
   wait(1)
   print("Burger")
end

local function Function2()
   print("Fries")
   wait(1)
   print("Tacos")
end

Function1()
Function2()
Function3()
Function4()

print("Functions are done running.")

The issue is that I need to wait until all the functions finish running to print ("Functions are done running.")

Is there a way I can print it and run the functions at the same time ?

you can use the task library for this. task.spawn(f) puts function f on its own thread and runs it. If you spawn the functions you can achieve this. You could also use coroutines but in this case it is not necessary.

2 Likes

Alright, I will try that right now. Thanks for helping! :smiley:

Worked perfectly as I wanted to. Thanks you very much!

Yes. Adding to what @mc3334 said above, here is how:

local function Test1()
print("hi")
end

local function Test2()
print("bye")
end


task.spawn(Test1)
Test2()

1 Like

AHH! NO! Unnecessary step!!! Do this:

function foo() end

task.spawn(foo)

There’s no need to wrap a function in a function just to task.spawn it

2 Likes

Phew thank you, I got stuck with that for a while :wink:
Here,edited.

1 Like

Hmm also I know this isn’t the post’s point but it says "Interval is empty" where there is the math.random

Is there anything wrong?

flip your numbers. You need (-20,-10)

min,max

there is no number greater then -10 but less then -20, which is why you must flip them

1 Like

In negative numbers -

The bigger the number is, the smaller it is. Thus : -20 is smaller than -10.

1 Like

Oooo okay thank you :blush:

character limit, just ignore : )