✓ Accepted answer
###What are parameters?
Parameters are the input for functions. They are predefined data holders for the arguments that the function will be called with.
function blah(a)
print(a+2);
end
blah(5)
###How do they differentiate between events?
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.
ex
Here's a couple examples -
- Touched event : returns the part that touched
function onTouch(hit)
print(hit.Name.." touched "..script.Parent.Name)
end
script.Parent.Touched:Connect(onTouch)
- MouseClick event : returns the player who clicked
function onClick(who)
print(who.Name.." clicked "..script.Parent.Name);
end
script.Parent.ClickDetector.MouseClick:Connect(onClick)
- PlayerAdded event : returns the player that joined
function onPlayerEntered(plr)
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)
print(who.." said hi at "..when.." o'clock")
end
sayhi("Bob","2:00")
2 comments
Thanks, though, do you know how the multiple parameters work?
edited