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

How to check if the number generated is a multiple of 5?

local number = math.random(20,80)
if number == 20 or number == 80 then
	print("Scouted stat limit reached")
end

I wonder if there is a more efficient way to find if the number is 20,25, 30, 35, 40, 45, 50, 55, 60, 65 ,70, 75, or 80. Typing a lot of if and or statements would take quite a while.

2 comments

0

divide the number by 5 and check if there's a decimal

2

Did you know that you could do a google search and find this out in 10 seconds or less?

1 answer

✓ Accepted answer

You can simply use the modulus operator. Example:

if number % 5 == 0 then
--code
end

It just divides by the number you provide and returns the remainder. If the remainder is 0 you know that it is divisible by five or whatever number you put in. I hope this helps and have a great day scripting!

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