super noob question but im new so shaddup :C.
how do i make a wait() do random between 2 numbers?
for example click something and it waits between 1 to 5 seconds before doing the next block of code?
While this question might be nooby(no offense), this thingy that we'll learn will be super useful in your scripting career
We'll be using the math.random
property of math
If we read what the wiki says(you can go to the wiki by pressing math.random in the second sentence), it says:
here is a random number generator in Roblox that seems to generate random numbers. But do a test, and insert this script into your place:
for _ = 1, 10 do print(math.random(100)) wait(1) end
alright! now we know that math.random
is quite a helpful thingy!
but, there's a catch, math.random gives similar(if not the same) numbers everytime!
so, how could we get around this?
The math.randomseed
property of math
we'll use that to randomize our random number even more!
math.randomseed(tick())
math.randomseed
takes an argument 'seed', which is easy to give, just use tick().
So? now what?
by taking what we learned today, we can combine them together.
math.randomseed(tick()) --To make random randomer wait(math.random(1,5))
Now we have a random timer!
*Note to use math.randomseed BEFORE you use math.random
Firstly, if you want to have a random number wait time, we will use math.random.
math.random(num1,num2)
In this, num1 is the minimum the random can be, and num2 is the maximum. So for example, lets have 1 as the minimum and 10 as the maximum. And print it.
print(math.random(1,10))
This will print a random number between 1 and 10. But it we want it to wait that amount of time, we will have to put the math.random()
inside the wait.
wait(math.random(minimum,maximum))
And voila! A random wait time with a minimum and a maximum.
wait(math.random(1,5))
Try that.