Math, Parameters, Arguments, and Return Statements in Roblox

·

·

Welcome back to my Roblox beginner scripting tutorial guide! I’m Jaden, and in this guide we’ll be talking about four things that all link to each other to make this one video: math, parameters, arguments, and return statements. This is one of the more important episodes, so I really want you to pay attention.


Discovering Math

First thing we’re going to start with is learning about math. I’m going to assume that you know the basics—addition, subtraction, multiplication, and division. If you don’t know those, I don’t think you’re ready for this video (sorry to tell you that), but if you do, we can continue with this tutorial guide.

What we need to do is insert a new script. Go to the Workspace, hit the plus sign, search for “Script,” and insert it. Rename this script to math, delete the default print("Hello world"), and you’ll have a clean canvas.

Inside the script, write:

local addition = 2 + 2
print(addition)

When you hit play, you’ll see 4 printed in the output. That’s because 2 + 2 = 4. You can replace the plus sign with a minus (2 - 2 = 0), an asterisk (2 * 2 = 4), or a slash (2 / 2 = 1). Those are the basics of using math in your script. Fantastic. Now we’re ready for the next part: parameters and functions.


Parameters & Arguments in Functions

Disable your math script, re-enable the script from the last episode (the one with function in it), and let’s go behind the curtain.

Clear out everything inside that script. We’re creating a brand new function to add two numbers together. Start typing:

local function addition()
end

Inside the parentheses, we can add parameters. These are variable names you can pass into the function. Let’s call them numberOne, numberTwo:

local function addition(numberOne, numberTwo)
local result = numberOne + numberTwo
print(result)
end

Here, numberOne and numberTwo are parameters—placeholders. Now below this, we call the function:

addition(5, 2)

These 5 and 2 are arguments. When you run the game, it prints 7 because it took our arguments, added them with the parameters, and printed the result.

Try calling the function multiple times:

addition(3, 2)
addition(9, 4)

Each call prints a different result based on the arguments. That’s the power of parameters and arguments in action.


Return Statements: Fetching the Function Output

Next, let’s bring in return statements. This lets your function compute something and send the result back where you called it.

Replace the print(result) inside your function with return result:

local function addition(numberOne, numberTwo)
local result = numberOne + numberTwo
return result
end

Now, outside the function, create a variable to capture the output:

local printResult = addition(8, 2)
print(printResult)

Here, addition(8, 2) returns 10, which gets stored in printResult, and then printed. Return statements send the computed value back to the caller—powerful stuff!


Final Tips & Your Challenge

Before we finish, it’s super important to save your work. Go to File → Save, or press Ctrl+S to keep everything intact.

For today’s learning objective, I want you to create more functions—try subtraction, multiplication, division, or add a third parameter like numberThree. You could even make functions that don’t return results. There’s a ton of possibilities.

Once you’ve built your own variations, drop your code in the comments. I’d love to see what you come up with. If you made it this far, congratulations—these are some of the most important and difficult concepts to grasp early on.

That’s it for this episode. I’ll see you in the next one—take care!