I've always wonder how the OnTouch Function works in Roblox Lua. Could you write out the script and explain each line of code? Thx.
COMMUNITY QUESTION
How does OnTouch Work?
1 answer
function OnTouch(hit) -- The start of the function, hit or anything else within those brackets is used for
-- interacting with the player that activated the function.
-- Code goes in here, for example, hit.Parent.Humanoid.Health = 0
end -- Ends the function
script.Parent.Touched:connect(OnTouch) -- In this example the script is inside a brick that you touch,
-- 'Touched' an action that triggers the function, connect is like connecting to the "function service" -- --- (doesn't exist) and OnTouch is the function your triggering.
FYI, functions only work when they are in the same script as the trigger is in.
This discussion is preserved as it was. New answers, comments, and votes are closed.
