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.
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.
lua
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.