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

Making an if statement for multiple math.random numbers?

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

✓ Accepted answer

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.

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