Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to pick random amount of time?

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

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.