I just want to make sure I have an understanding of it all
function onTouch(part) -- states the function local humanoid = part.Parent:FindFirstChild("Humanoid") if (humanoid ~= nil) then humanoid.Health = 0 end end script.Parent.Touched:connect(onTouch) -- if a person touches the brick then run the function
You're connecting the function to the Touched event, so every time the brick is touched the function will fire.
The final line,
script.Parent.Touched:connect(onTouch)
is a connection.
You are calling the function connect
(indicated by a name + parenthesis: connect()
).
When connect
is called, it tells ROBLOX to remember the function you gave it (you gave it onTouch
).
Then, when something touches the part, ROBLOX will internally then call what you gave the connect
method (so it calls onTouch
)
The line
function onTouch(part)
means nothing special on its own. You just define a function with one parameter, and set the names of them to what you want.
You could also say
funcToConnect = onTouch; script.Parent.Touched:connect(funcToConnect);
and it would behave the same as the original.