script.Parent.Touched:connect(function(part)
--What does part mean?
'part' is the parameter or argument of the function. It is whatever the event is triggered by.
For example, anything that triggered the 'Touched' event will be the 'part' argument.
If you used the argument in your function, it will do whatever you want it to do to the argument ("Block" in the above example).
script.Parent.Touched:connect(function (arg) -- The argument can be anything; it's a variable. arg.Transparency = 1 -- Will make anything that touches the brick invisible end)
script.Parent.Touched:connect(function (asdfadsf) asdfadsf.BrickColor = BrickColor.new("Really red") -- Will change the argument's color to really red end)
Parts have a Touched
event attached to them.
An event is an object describing some future action that you can attach code to.
Events have a :connect
method (a function that you can call on it, just like :Remove()
or :Destroy()
or :FindFirstChild()
).
You give the :connect
method a function as its parameter.
A bit simple syntax looks like this:
function myfunc(other) print(other, "touched me!") end script.Parent.Touched:connect( myfunc )
We're telling Touched
to fire the function we gave whenever the event happens. Since we gave it myfunc
, that means myfunc
gets called whenever something touches script.Parent
.
It passes 1 parameter to that function, which is the part that is touching it (called other
in the definition of myfunc
)
"Part" is the part that the "Parent" touches. Say the parent is called A, and the part that gets touched is called B. Whenever A touches any part, it'll set the part as a variable called B. This is an example script:
script.Parent.Touched:connect(function(B) print(B.Name) --If the part that the "Parent" touches is named "Part", then the game will print "Part". end) --Remember to add the closing parentheses to let the function run correctly.
Hope this helps. If you have any questions or problems, please leave a comment below. :P