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
01while true do
02 
03   wait(math.random(1, 4))
04 
05      print("num1")                                           
06 
07   wait(math.random(1, 4))
08 
09      print("num2")
10 
11   wait(math.random(1, 4))
12 
13      print("num3")
14 
15end

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:

1while true do
2    wait(math.random(1, 4))
3    wait(math.random(1, 4))
4    wait(math.random(1, 4))
5 
6    print("num1")
7    print("num2")
8    print("num3")
9end

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:

1while true do
2wait(1)
3spawn(function()
4wait(math.random(1,4))
5print (“bruh”)
6end)
7end

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