Checking if a number is in 2s

Hi, I would like to know how can I check for if a number is in the 2s times table, because I want to try and do something when someone levels up every 2 levels, so let’s say if they’re level 2 they get a boost, then if they’re level 4 they get a boost and so on, so how can I check this?

You can check if number % 2 == 0
Or if the remainder of the division between “number” and “2” is 0

1 Like

if (num%2) == 0 then
replace “num” with your number

2 Likes

Use the modulo operator to achieve this, which in Lua is denoted by a single percent sign (%), so for any number n where the following formula is valid: n % 2 == 0 n is a product of 2. The value which results from use of the modulo operator is the remainder of the second value (the value after the operator) divided by the first value (the value before the operator).

2 Likes