Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make a script run multiple functions at once?

while true do

   wait(math.random(1, 4))

      print("num1")                                            

   wait(math.random(1, 4))

      print("num2")

   wait(math.random(1, 4))

      print("num3")

end

The script would wait the randomly given time and then it would print the "num1" and it would move on to num2 then after some time num3, but how do I make it so it prints all 3 numbers at the same time with the math.random function in one script?

1 comment

0

I'm not sure what you're asking. There's something called coroutines which will allow you to run multiple functions at once. (execute function1() function2() and function3() all simultaneously) which might be what you're asking but I'm not sure

2 answers

I'm not completely sure if I understood what you're asking correctly, but based on how I interpreted your question, I think this code would work for you:

while true do
    wait(math.random(1, 4))
    wait(math.random(1, 4))
    wait(math.random(1, 4))

    print("num1")
    print("num2")
    print("num3")
end

Also, if num1, num2, and num3 are variables, you'll want to change the prints to print(num1), print(num2), and print(num3).

3 comments

0

This script means wait 3 - 12 seconds later and then print num1 , num2 , num3. That doesn't have any random number prints and waste time to wait.

0

He wants the script to wait, it seems.

0

I don't know, question seems too vague

Try using this:

while true do
wait(1)
spawn(function()
wait(math.random(1,4))
print (“bruh”)
end)
end

I typed this script on my phone btw so could be wrong

Spawn calls a function on a new thread, meaning that there is no wait for the function to return, so more than 2 processes can happen at once

Accept this answer if worked

This discussion is preserved as it was. New answers, comments, and votes are closed.