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

Is it possible to make a Random Wait() Timer?

Asked by 4 years ago
Edited 4 years ago

I want to understand the consept of > Math.Random

However i want to do an example of this But in a Advance way

while true do wait(0.1) print('Is_On') wait(0.1) print('Is_Off') end

I want it to be a random wait timer instead of an event occurring every wait(0.1) Time.

This timer that i am trying to conduct should Instead of Wait Time, Should be ticket to random seconds to functions these operations.

for x = 1,2 do wait(math.random) print('Is_On') wait(math.random) print('Is_Off') end

3 answers

Log in to vote
0
Answered by
Mr_Unlucky 1085 Moderation Voter
4 years ago
for x = 1,2 do 
    wait(math.random(1,5)) 
    print('Is_On')
    wait(math.random(1,5))
    print('Is_Off') 
end

Since this is the code you put, what I did was edit the waits so it has both parameters since if you left it like that it would probably give an error.

0
Ah, i see how you did it now! Thanks! S0NIC_Dev 61 — 4y
Ad
Log in to vote
0
Answered by
Yuuwa0519 197
4 years ago
Edited 4 years ago
math.Random()

is a function that runs by inputed arguments inside parenthesis. Therefore, you will have to state the range of numbers that you want to generate, for example,

math.Random(1,10)

will return any numbers between 1-10.

Log in to vote
0
Answered by 4 years ago

If you want some more variation in math.random, trying to simply input decimal values into math.random won't work. That's because math.random only supports integer values, which means that decimal values can't be inputted. However, it is possible to divide the value math.random returns.

math.random(1,100)/100 --Returns a value between 0.01 and 1.00

Answer this question