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

Math are hard as well?

How do i detect if a number is a multiple of 2?

1 comment

0

i need help!

3 answers

✓ Accepted answer

using the modulus operator What the following code says is 'if the remainder of a number divided by two is 0, then it is divisible by 2 otherwise there is a remainder of ____'

number = 16

if((number % 2)==0)then
        print("divisible")
else
        print("there is a remainder of ", number%2)
end

3 comments

2

this time you beat me to it lol. and yours is much better than mine

0

????????????

0

that was a pointing fingers emoji not sure why it defaulted to question marks.

You would use "no % 2" so it would be something like this:

print(1%2 == 0) -- prints false because it's not even
print(2%2 == 0) -- prints true because it's even
print(3%2 == 0) -- false
print(4%2 == 0) -- true

I think that the % operator gives you the remaining of a multiplication or something but I am not sure

You can use the modulus operator(%), which finds out the remainder in division, such as

6÷4=1...2

is equal to

6%4=2

You can use it in this way:

local num = 8
if num%2 == 0 then -- Checks whether the remainder of 8/2 is equal to 0
-- Do something here
end

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