I've been scripting for a few months, and I know how scripts work such as if someone writes
part = game.Workspace.part part.Touched:connect(function(hit) hit.Parent.Humanoid.Health = 0 end)
it'll kill the character and hit is the person who touched the part.
But when you're using GUIs and there are three parameters, I'm starting to wonder what these actually are so that I can use them correctly.
Can anybody describe them for me?
Parameters are the input for functions. They are predefined data holders for the arguments that the function will be called with.
function blah(a) --Parameter print(a+2); end blah(5) --Argument --Output: 7
Parameters for the functions that you connect to events are extremely useful, and most of the time a necessity for your code. These represent whatever the event returns.
Here's a couple examples -
function onTouch(hit) --Parameter for event print(hit.Name.." touched "..script.Parent.Name) end script.Parent.Touched:Connect(onTouch)
function onClick(who) --Parameter print(who.Name.." clicked "..script.Parent.Name); end script.Parent.ClickDetector.MouseClick:Connect(onClick)
function onPlayerEntered(plr) --Parameter print(plr.Name.." joined the server!"); end game.Players.PlayerAdded:Connect(onPlayerEntered)
-Edit-
To define multiple parameters, separate variable phrases by ,
commas.
function sayhi(who,when) --multiple parameters separated by commas. print(who.." said hi at "..when.." o'clock") end sayhi("Bob","2:00") --call it with multiple arguments --Output : Bob said hi at 2:00 o'clock