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

Making an if statement for multiple math.random numbers?

Asked by 4 years ago

I'm trying to make a game with randomized powers. I know how to make a math.random script, but it's not very efficient. For example:

local PowerMath = math.random(1,100)

if PowerMath == 1 then

end
if PowerMath == 2 then

end

I wanted to know if there is a more efficient way of making a math.random instead of having to make a script for each number. Is there a way to say if math.random == 1-50 so I don't have to make an if statement for numbers 1-50?

1 answer

Log in to vote
0
Answered by
valchip 789 Moderation Voter
4 years ago
Edited 4 years ago

If I understood the question correctly, you basically want to run a specific code if the randomized number is less or equal to 50, if that is the case you can use the less or equal to sign. So:

local number = math.random(1, 100)

if number <= 50 then
    --code
end

If the number is 1, 9, 36, 40 etc.. (a number equal or less than 50) the code above will run, if that is not the case it will not.

Ad

Answer this question