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

Getting the part that got touched?

Asked by
Scootakip 299 Moderation Voter
3 years ago

Hi! I know it's possible and easy to get what touched a part when calling for a function through Touched, but is it possible to get that part that called the function? That might've been a bit confusing to read but it's the best way I can describe my question

for i,v in pairs(game.Workspace.Cameras.TouchParts:GetChildren()) do
    if v.ClassName == "Part" then
        v.Touched:Connect(TouchedPart)
    end
end

This is my code, it calls the function TouchedPart when any Part in Cameras.TouchParts get touched. I need to know which part was actually touched and called the function. Is there a way to do this within the touched connector? If not, anyone got any ideas for getting that?

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Maybe inside the function write this?

if TouchedPart.Name == "Part" then
-- write some code here
end
0
oops, meant to write TouchedPart. 1OXGAMER 0 — 3y
Ad

Answer this question