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

How do I determine the part that was touched in a touched event?

Asked by 9 years ago

I'm using a for loop to apply to all parts in a model. Also, I'd like to ask how to determine if a part is continuing to touch the part.

1 answer

Log in to vote
0
Answered by 9 years ago

To have a Touched event trigger, you need to have the part that got touched. E.G

game.Workspace.Part.Touched:connect()

But, for Touched events, it has a parameter that is by default, whatever triggered the event, so:

game.Workspace.Part.Touched:connect(function(h)
    if h.Parent:FindFirstChild("Humanoid") then
        h:remove()
    end
end)

TouchEnded is another event, which is fired once the part stops being touched, so:

local touching = false
script.Parent.Touched:connect(function()
    touching = true
end)

script.Parent.TouchEnded:connect(function()
    touching = false
end)

http://wiki.roblox.com/index.php?title=API:Class/BasePart/Touched

0
Well... No way to determine the original part? I'm using a for loop to apply the function to all the parts in a model. RandomCraftER2002 0 — 9y
0
The original part? TheDeadlyPanther 2460 — 9y
Ad

Answer this question