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

How can I test for when two parts touch?

1 answer

✓ Accepted answer
local part = script.Parent
part.Touched:connect(function()
    local touching = part:GetTouchingParts()
    for parts,touchingpart in pairs (touching) do
        print(touchingpart.Name)
    end
end)

This script prints the names of all parts that touch the part

local part = script.Parent
part.Touched:connect(function()
    local touching = part:GetTouchingParts()
	if #touching == 2 then
		--script here
	end
end)

this script executes your code when 2 parts touch the part

this sometimes bugs so i would prefer to use this:

local part = script.Parent
wait ()
while true do
    wait ()
    local touching = part:GetTouchingParts()
	if #touching == 2 then
		--script here
	end
end)

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