I already have the random part done, I just need to make sure that the number is divisible by 4. And if it is not, make it
Simply use the modulus operator and to make it do it again until the number is divisible just use a repeat loop. Example:
local ranNum repeat ranNum = math.random(1, 100) until ranNum % 4 == 0 -- modulus returns the remainder so if the remainder is 0 you know that the number is divisible by four
I hope this helps and have a great day scripting!
Hello, waffle792!
You can get %
to get the modulus, and then test if it is equals to 0
print(6 % 4 == 0) -- This will print false print(400 % 4 == 0) -- This will print true
After testing, if the number is not divisible by 4, just run the random part again, I would make it a function if I am you
Good Luck with your games
A number is divisible by 4 if it's in the form 4k
where k is any integer.
Don't "keep generating random numbers" that's stupid, just generate a random integer and multiply it by 4.