welcome back to my Roblox beginner scripting tutorial guide my name is balev and in this episode we'll be talking about four things that all link to each other to make this one video those being math parameters arguments and return statements but we're going to go through each of them one by one inside of this episode and it's going to be one of the more important episodes so I really want you to pay attention to this episode so first thing we're going to start with is learning about math now I'm going to assume that you know like the basics of math with operations like addition subtraction uh multiplication and division all those sorts of things if you don't know how to do those things well then I don't think you're ready for this video I'm sorry to tell you that um but I'm going to assume that you do know those things so if that is the case then we can go ahead and continue with this tutorial guide so what we're actually going to do is go to the right side and uh disable our function script and we're going to go through the same thing which is hitting the plus sign in the workspace searching up for a script we're going to insert that and then we're going to rename this script so right click on it and then rename to math enter just like that okay and I'm also going to delete this statement right over here so I'm going to hit contr a and then delete just like this so when we're working with math um so in this case it's going to be basic operations like addition subtraction all those other things we basically take two numbers and then we do the operation that we specify in between those two numbers and we can do this um by having a variable if we want want um that to be the case uh so what we can do is write a variable so we're going to say local and we can make this an addition variable so we can call this uh just simply addition but you can name this whatever you want to be um we're going to set this equal to two numbers with whatever um operation we decide to use for this statement so what we can do is put two numbers here so we can say uh let's say two and then we're going to say plus so this is going to be a plus sign indicating addition plus 2 just like this and if we were to print the statement so if we were to say uh print open close parentheses and then we throw in addition over here just like this and we go into the game hit play then what we should see in the output is the number four so if you click on it we can see that if we put two and then we put a plus sign with another two then that's going to be an addition of 2 + 2 which is equal to 4 and that's going to be set equal to addition and it's going to print that inside of the output uh with this addition variable so I'm going to hit stop and that is the basics of using math uh inside of your script but there are other operations we can use so if we were to let's say use uh subtraction then we would replace this uh plus sign with a minus symbol just like this which is 2 minus 2 or we can replace this with the asteris so if we hold shift 8 then this is what the multiplication symbol looks like for 2 * 2 which is 4 uh or we can replace this with the division symbol which is going going to be a forward slash so 2 / 2 is equal to 1 and so that's what it would print out inside of the output here so that's the basics of using math but this is going to be very helpful for the next two things we're going to be talking about which is going to be parameters and functions so what I'm going to do is go back to our game and I'm actually going to uh disable our new math script that we just created and I'm going to reenable our function script over here so this is the script we created in the last episode now if you were and now if you remembered how a function is created we basically have a local keyword with the function declaration right here and then the name of the function over here and then we have open and close parentheses so what's interesting about these open and close parentheses is that we can add parameters inside of these open close parentheses so that we can use whatever is contained inside of these parameters in this function um to get different results depending on uh what we use to call this function with now that may sound confusing to you at first but once we um use this in practice uh it'll make more sense so what I'm going to do is delete everything that we've had in the script so far so I'm just going to hit backspace just like this and we're going to create a new function that's going to add two numbers together so what I'm going to do is say local function and then we're just going to call this um just anything really we're going to call this addition open and close uh open close parentheses I'm going to select the right side and then hit enter just like this and I'm going to go down here and then call the addition function just like this addition open close parenthesis and now we have our function declaration and also our uh function call right over down here so this looks pretty similar to what we worked with in the last uh function that we created but this time we're going to add parameters now basically what a parameter is it's basically a value that we can pass into this function so that we can use this value to make calculations within this function that we're calling um and so the way we separate these values is by and the way we create these values is by giving a name for each of these parameters so uh if we wanted to add two uh numbers together what we can do is um basically make the name for our first number parameter so what we can do is say uh number one just like this uh but we can really call it whatever we want we can even say num one and we can even say N1 but for this example we're just going to say number one like this and each value that we add into this is going to be separated by a comma so I'm going to add a comma space and then we're going to add the second number to here so we're going to say number two just like this and so these are our parameters that we can put inside of here so that we can make our addition calculation so now what we're going to do here is with these two numbers that we um have thrown into this addition function we can create a result of the addition of these two functions so we're going to say local result or we can call this whatever you want uh equals number one plus number two you can kind of think of these two numbers as variables uh for numbers that we pass into here and so we basically add these two numbers together to get our result and so we can now print our result um variable that we just created which is the result of these two numbers being added together so now that we've added parameters what we need to do is add arguments to this function so that it's um basically represented as these two numbers right here now what I'm talking about here is if we go down to um the open close parentheses inside of our function call uh we can see that Roblox is telling us that we need to add a number for number one and we need to add a number for number two so in this case we can add two numbers let's say five and we can replace this with a comma and then roblo is going to tell us that we need a number two as well so we can put in let's say two so basically this is an argument and this is a parameter the difference between uh arguments and parameters is that parameters is what we use to um basically create our variables inside of our function declaration and this is how we make our calculations the arguments is going to be what values we throw into this function um for the calculations that we're going to create inside of here so as a result of this what we're going to do now is go into the game and hit play and what we should see in the output is the number seven because what we did was we took number one and number two we passed them in as the first argument for number one which is five and then the second argument for the the for number two which is two we add them together and then we print out the result I hope this part is making sense to you so far um it's a very important concept you need to know about and this isn't restricted to just numbers you can literally put in any um values you want inside of here so this could be um let's say a string which is going to going to be whatever it is or it could be a Boolean as well it doesn't really matter what it is um as long as the calculations are accurate CU obviously you can't calculate um a string plus a number but and you also can't calculate a Boolean plus a number as well so you have to make sure that whatever you pass inside of here is accurate to your calculations that you try and make and I hope this part has made sense to you up until this point we can even do this multiple times by dropping a line and then uh calling the addition function again so we can put in let's say three as the first number and then two as the second number and we can even add another addition function right here which is let's say um nine for the first number and then four for the second number if we go into the game and hit play then what we should see in the output is different results depending on the numbers that we gave this function so now this function gives different results based on the arguments that we give it versus is giving us the same result every single time we call this function which is why parameters and arguments are very powerful when it comes to uh adding these inside of your functions when you make them inside of your scripts now there's one final thing we're going to do before we end off this video and that's going to be introducing return statements now basically what a return statement is is it's a value uh when it gets calculated it's going to return that value so that it's going to go back into where uh we called this function now I don't know if that completely made sense to you but if I showed you through uh scripting then I think uh you'll be able to understand it better so what I'm going to do is delete these function calls to make this um more simple and instead of printing this result value what I'm actually going to do is return this result once we calculate um what number one plus number two is so I'm going to delete this print statement and what I'm going to do instead is say return in all lowercase and then we're going to return this result so we're going to say result just like this and so this is uh our return statement now what does this return statement do well it Returns the results of the calculation that we created back to where we called this function so what we can do is create a variable that is attached to this function call so that we can take that value and then print it ourselves outside of this um function so what we're going to do is say local um we can call this print result just to make this um uh just to differentiate this between this result and we're going to set this equal to the function itself so we're going to say addition open close parentheses and we can put in uh whatever two numbers we want inside of here so we're going to say eight and then for the second number we're going to say two just like this um as we separate these by commas and this is basically how we get the result um it's by calling this function and then um once we um add these two numbers we return the result so it's going to go back into here and that's what print result is going to be set equal to so now if we go down here and then uh write our print statement with print result just like this if we go into the game hit play then what we should see in the output is 10 because uh we did exactly what the script is supposed to do with return statements so we create a variable on the outside we set this equal to addition with our two numbers right here uh these two numbers are then added and then we use this return statement to return the result back to the print result variable and so now we are printing that result and that is how we use return statements inside of Roblox Studio I hope this part has made sense to you so far um and if it has this has been one of the more difficult uh things to learn about so um so I can commemorate you if you've been able to follow along up until this point so now what I'm going to do is hit stop and that is basically going to be it for this episode now I want you to keep in mind that up until this point we haven't really been saving our work um it is very important to save our work after we do anything important so that we don't lose any progress so I'm going to go hit file and then we're going to hit save to file now you can also uh hit contrl s uh s for snake so that we can uh save our game whenever we make changes to the game so that's one more thing I wanted to add before we ended off this video for today's learning objective what I want you to do is um make more functions so I want you to make a function for subtraction um you can even do multiplication and division as well uh or you could even add more uh numbers to add as well so you can have another uh parameter right here so number three and you can do more calculations like dividing number three or something uh there's a lot of possibilities you can have with this you can add more parameters um you can make more functions uh that returns results or doesn't return results um you have a lot of capabilities and leeway for this little Lear objective so I hope you make something really great out of this learning objective and once again go down to the comments once you're finished and paste in uh whatever code you made so that other people can see what you've been doing that you're comfortable sharing so with that being said that's going to be it for this episode I will see you in the next episode take care