Number Arithmetic & Compounds Assignment

✏ Beginners Scripting Guide ✏

https://create.roblox.com/docs/luau/operators#arithmetic https://create.roblox.com/docs/luau/operators#compound-assignment In this section, we will be discussing number arithmetics. Number arithmetics can be used to create a math expression for your script. Here are the tables.

ARITHMETIC

Operator
Operation

/

Division

*

Multiplication

+

Addition

-

Subtraction

%

Modulus

^

Exponent

COMPOUNDS ASSIGNMENT

Operator
Operation

+=

Addition

-=

Subtraction

*=

Multiplication

/=

Division

%=

Modulus

^=

Exponentiation

HOW ARITHMETIC WORKS

Division - Division can be used to divide numbers. Multiplication - Multiplication can be used to multiply numbers. Addition - Addition can be used to add numbers. Subtraction - Subtraction can be used to subtract numbers. Modulus - Modulo can be used to find a reminder of a division. Exponent - Exponent takes two value called base and power.The base is mulitplied with itself for power times (ex: 5^2 = 5*5)

BASIC USAGE

This is how you should use arithmetic and compound assignments in a script.

DIVISION

local Number = 2
print(Number / 2) -- 1
Number = 4
Number /= 2
print(Number) -- 2

MULTIPLICATION

local Number = 2
print(Number * 2) -- 4
Number = 4
Number *= 2
print(Number) -- 8

ADDITION

local Number = 2
print(Number + 2) -- 4
Number = 4
Number += 2
print(Number) -- 6

SUBTRACTION

local Number = 2
print(Number - 2) -- 0
Number = 4
Number -= 2
print(Number) -- 2

MODULUS

local Number = 2
print(Number % 2) -- 0
Number = 4
Number %= 3
print(Number) -- 1

EXPONENT

local Number = 2
print(Number ^ 2) -- 4
Number = 4
Number ^= 3
print(Number) -- 48

Last updated