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

Better way to check a range of numbers?

I wasn't completely sure how to word this title but pretty much I have a random number generating then I check what it came up as. Pretty much I'm wondering if theres a way to check if it is a number between say 1-5 rather than typing it all out. Hers part of the script to better show what I mean.

	local sp = rng:NextNumber(1, 6)
	wait(5)
	if sp == 1 or 2 or 3 or 4 or 5 then

Is there a way to check that range rather than typing one through five?

1 answer

✓ Accepted answer

use relational operators.

if sp >= 1 and sp <= 5 then 
	-- your stuff here
end

the code checks if the random number is more than or equal to 1 and less than or equal to 5. good way to check a range of numbers.

2 comments

0

if num > 0 and num < 6 then :P

0

As a style aside, I find 1 <= sp and sp <= 5 much easier to read

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