(Please forgive my horrible avatar, this is only an alt account . I was afraid this site was used for phishing.) Let's say I have a block that starts a function when it's touched. How can I get the block that touched it? I think I know, but I haven't tried this yet. If it works, I will close this question. Do I just add the variable name of the touching part in the () argument of the function?
COMMUNITY QUESTION
How can I get the block that touched an onTouch block?
2 answers
Part = ???? --this is what part will fire the function when it is touched
Part.Touched:connect(function(PartHit) -- The "PartHit" is the part that hit the part you put in "Part", it doesnt have to be named "PartHit" it can be anything else
--and put what ever you want it to do here
end)
Yes! Using the TouchedEvent, you can get the part that touches an object!
script.Parent.Touched:connect(function(hit)
print(hit.Name.." touched me!")
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
You've pretty much got the right idea. The first argument of the function will be whatever the event returns, and that is different for each event. With the Touched event, the argument passed is the brick touching it.