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

How to do math, please?

What is math for scripting?

2 answers

✓ Accepted answer

You can add, subtract, multiply, and divide like normal.

local var = 2 + 2
print(var) -- 4
local var = 2 - 2
print(var) -- 0
local var = 2 * 3
print(var) -- 6
local var = 2 / 2
print(var) -- 1

To check what a value is equal to you use two equal signs.

local bool = 2+2 == 4
print(bool) -- true, 2+2 equals 4

Please vote me up and accept me as the answer if you found this helpful. Thank you for taking the time to read this!

4 comments

0

What is * and / mean?

0

Works!

1
  • is multiplication, and / is division. So 3 * 2 is 3 multiplied by 2, and 3 / 2 is 3 divided by 2
0

Cool , thanks!

Like the answer above says there's the basic math operators found in most programming languages (adding, subtraction, multiplication and dividing) but also in lua there is other functions that will do more complex code, such as finding the sine of a number.

The link below is by a website goes through all the more complex functions that are available in lua, I suggest you give it a read: http://lua-users.org/wiki/MathLibraryTutorial

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