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

How to pick random amount of time?

Asked by 4 years ago

I am trying to create a missile that explodes after 0.2, 0.3, or 0.4 seconds. I tried doing:

wait(0.2, 0.3, 0.4)

,but it explodes after the amount of seconds that was listed first (0.2).

Is there something else I need to do?

1 answer

Log in to vote
0
Answered by
Abandion 118
4 years ago

wait() only takes 1 argument; the amount of time in seconds. If you'd like to generate a random number, you can do so with Lua's math library. As math.random fetches a random integer, you'll need to divide by 10, like so.

rand = math.random(2,4) / 10
wait(rand)

Here's a reference for Lua's math library http://lua-users.org/wiki/MathLibraryTutorial

Ad

Answer this question