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

How do i make a range of numbers to save time in a randomizer?

Asked by
lilzy7 68
4 years ago
while true do
local luck = math.random(1,100)
if luck == 1 then
print ("Very Lucky!")
elseif luck == 2    -- how do i make it range from 2 to 50??? i don't want to waste my time doing == 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9 or...


1 answer

Log in to vote
1
Answered by
Nowaha 459 Moderation Voter
4 years ago
Edited 4 years ago

For a range you can use the "greater than" (>, >=) and "less than" (<, <=) symbols, and the "and" word.

The "and" makes sure that all of the situations in the if statement are correct.

This is an example for checking if a number is between 2 and 50, including 2, excluding 50:

if luck >= 2 and luck < 50 then
    -- If luck is greater than or equal to (>=) 2, AND luck is less than 50, then...
end

If you also want to include 50 you can also put a <= instead of < there.

On a side note, I see that this is inside of a while true do loop. Make sure you put a wait() inside of the loop to avoid your studio freezing and crashing.

Ad

Answer this question