Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I get the block that touched an onTouch block?

Asked by 8 years ago

(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?

1
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. aquathorn321 858 — 8y

2 answers

Log in to vote
2
Answered by
lucas4114 607 Moderation Voter
8 years ago
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)
Ad
Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
8 years ago

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)

Answer this question