function hi(hello) end
What does the "hello" do in the first parameter do in the function?
Parameters are what you pass to a function using the function's parenthesis ()
. The function's parenthesis serve as a tuple of arguments to have parameters passed to them.
If the function is called via an event firing, the parameters are already there. Example:
script.Parent.Touched:Connect(function(part) -- Stuff here end)
Because Touched
passes the part the touched the part firing the event as its parameter, there is a point to adding it in a local function or such without having to define that parameter because Touched
already defines it. Here's what I mean:
local function onTouched(part) if game.Players:GetPlayerFromCharacter(part.Parent) then print("Found a player") end end script.Parent.Touched:Connect(onTouched)
When a function is defined and then called via the event (not created by the event), the event passes its parameters (if it has any) to whatever arguments are in the tuple ()
. For example, because Touched
only passes one parameter, you only need one argument.
But what if it's not called by an event but rather called by the scripter?
In this case, you have to tell the script what parameters to pass to the arguments. Example:
local function TeleportTo(x, y, z) script.Parent.Position = Vector3.new(x, y, z) end TeleportTo(5, 10, 10)
Because there is no event to fire to pass parameters, you have to define them yourself. Of course, this is only if the function is not called from an event but rather called manually.