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

Is it possible to use a NumberRange in an if statement? I can't seem to get one to work?

So I am trying to use a numberrange in a if statement, this is what I'm doing:

if player.leaderstats.Stage.Value == NumberRange.new(10,21) then
    print("yes")
end

When I test it there are no errors, but yes does not get printed? I can't find anything on the wiki about it? Any help would be much appreciated.

1 comment

0

What you're actually doing is checking if the value is equal to many numbers. A "range" of numbers is practically a list of numbers from the minimum to the maximum.

1 answer

✓ Accepted answer

It wouldn't make sense to compare a number to a huge bunch of numbers in a NumberRange because it will take forever and I doubt the compiler will approve of that. However, you can check if the number is greater than or equal to the Min of the NumberRange and less than or equal to the Max so you can know if the number is in range.

local val = player.leaderstats.Stage.Value -- To avoid repeating "player.leaderstats.Stage.Value"
local range = NumberRange.new(10,21) -- Store it in a variable because we are using this more than once.
if val >= range.Min and val <= range.Max then
    print("yes")
end

If you have any questions, feel free to leave them in the comments. I hope this will work.

1 comment

0

Ah, I see.. I understand now. Thank you!

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