Okay, so I have a basic knowledge about functions, and ROBLOX Lua in general. So while I was looking around in the forums, I noticed a lot of things like this
game.Players.PlayerAdded:connect(function(player)
I've read the ROBLOX Wiki to see if I could understand from what it says there, but I still have absolutely no idea. Some help would be much appreciated.
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.
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) --[[ The function 'Greet' can now take in an argument. The argument will be equivalent to 'String'. ]] print(String) end
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") --> Hello
Look in your output window, you should see the word "Hello" pop up.
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.