✓ Accepted answer
What is a Parameter?
A Parameter is any value taken in by a function. These are the same values that you will use as Arguments for calling the function.
How do I Define a Parameter?
The definition of a function's Parameters occurs in the definition of said function. The syntax for defining functions, as you may know, is this;
function [function_name] ()
[code]
end
See the parentheses former to the declaration of the function's name? Any and all parameters that you want the function to contain will be defined between the bounds of the parentheses.
function Greet(String)
print(String)
end
How Do I Use a Parameter?
The way I see it, there are two perspectives you must adapt while working with functions. The definition of the function, and the calling of the function.
To actually use a parameter you need to expand your perspective to the Calling side. The function that was defined above took in the parameter 'String', and printed it. So now all that's left is to call the function, and provide the arguments.
Greet("Hello")
Look in your output window, you should see the word "Hello" pop up.
Correlation to Your Example
Now that you have some insight on what parameters are, as well as how to define and use them, I can elaborate on your specific example;
game.Players.PlayerAdded:connect(function(player)
What you have provided here, is the definition of a PlayerAdded event. The parameter 'player' is going to be equivalent to whatever player had joined when the event was fired.
You can use the key phrase 'player' to access the newly added player.
2 comments
Oh, so from what you said, it seems that the parameter is a value that is assigned later in the script? This is one of the best explanations I think I've ever seen on this site. Thank you, kind sir.
No problem mayann.