I kind of understood them while learning python, but now I totally forget how they work and why.
function hi(x) y = x.Backpack z = script.Parent.Parent.Parent["Cup"] z:Clone().Parent = y end script.Parent.ClickDetector.MouseClick:connect(hi)
This example script does something arbitrary, but the thing I want to focus on is the part where is says
function hi(x)
Does the part at the bottom of the script where it connects MouseClick to the function automatically describe "x" as the character? Or am I missing something entirely?
When a function is connected to an event, the event may pass certain parameters. Mind you, you don't just know what these parameters are; you'll have to look at the wiki when you aren't sure of one. For example, the PlayerAdded event, when connected to a function, passes the parameter of the player that joined the game.
game:GetService("Players").PlayerAdded:Connect(function(player) print(player.Name) -->their name end) --Similarly with the **MouseClick** event of ClickDetectors, it passes the player that clicked. script.Parent.ClickDetector.MouseClick:Connect(function(player) print(player.Name) --note that MouseClick should only be used on the server end)
You can, of course, leave the parameters out if you deem them unnecessary for your situation. Additionally, they're just variables. This means you can call them whatever you want. In the above example, I referred to them as player because that's obviously the most reasonable name. I could have called it x, though, like you have done. Anyways, whenever you aren't sure of the parameter of an event, just check it on the wiki.