Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

2 comments

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.

0

The original part?

This discussion is preserved as it was. New answers, comments, and votes are closed.