Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to make a script run multiple functions at once?

Asked by 5 years ago
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?

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 royaltoe 5144 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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).

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. Xapelize 2658 — 5y
0
He wants the script to wait, it seems. hpenney2 53 — 5y
0
I don't know, question seems too vague sahadeed 87 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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

Answer this question