I only saw one animation in your script, so I can't really directly help you, though I can offer this information:
With anything random in lua, you'll probably want to use math.random
! math.random
is quite useful, and theres a few ways to use it.
If you just call math.random()
then you'll get a number between 0 and 1, obviously a decimal! Here are some examples of numbers I got when calling math.random
with no parameters:
0.47254860072634
0.79055146946623
0.85747856074709
0.48014770958586
0.98303170873135
Your next option is to provide one parameter, a number! This will generate a number between 1 and that number. This is called the "upper bound." The "lower bound," in this case, is 1.
1
3
2
2
1
And finally, you can supply two parameters, a lower and upper bound (in that order). The upper bound must be greater than (it can be equal to, but you'll just get the same number) the lower bound.
2 | print (math.random( 5 , 10 )) |
5
5
9
9
5
Note: If you try to use a number with a decimal as either an upper or lower bound, it'll be rounded away from 0 (1.5 -> 2, -1.5 -> -2).
With this knowledge, we know there's 2 ways to get a 50% chance.
- You can use
math.random()
and check if the number it returns is greater than or equal to 0.5, aka 50%
- You can use
math.random(1, 2)
and if the number returned is 1
then play the first animation, if the number returned is 2
then play the second.