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

How do i make math.random if statement have more than 1 number?

so im making this and it is using math.random my question is how do i make it detect more than one number like instead of 1 it could be 1-50 so how do i do this? here is the script.

local EggRan = math.random(1,100)
if EggRan == ???

1 comment

0

if EggRan > 0 and EggRan < 51 then

1 answer

✓ Accepted answer

To have more than one condition read by an if statement, you can use one of two keywords:

  1. and. This keyword tells the if statement to check if a and b is true. In the case of this keyword, a and b must both be true in order for the condition to pass. (You can have as many conditions with and as you like, just as long as each condition is separated by and.)
  2. or. Tells the if statement to check if either a or b. If a is not true, then check to see if b is true. If neither a or b are true, the condition does not pass. (Like and, you can have as many conditions as you want with or.)

In your case, you're checking if a number is between 1 and 50. You would use and:

if EggRan > 1 and EggRan <= 50 then
    -- Continue with the code if this condition passes
end

The above code checks for two things, both of which must be true for the condition to pass:

  1. The randomly generated number is greater than 1.
  2. The randomly generated number is less then or equal to 50.

For finding numbers within a range, you should always use math.random().

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