Issues - check if two parts have been touched

check if two parts have been touched

part1: is an instance part.
part2: is a part in the workspace that is there.

I need to be able to check if part1 has touched part2.

	part1.Touched:Connect(function(hit2)
		if hit2.Parent == part2 then
			print('part1 has touched to part2')
		else
			print('they have not touched yet')
		end
	end)

I need a hand, I’ve tried this and it still doesn’t work, any idea why?

If I understand what you mean, you just need to remove the “Parent” in your if statement. You are checking for the part itself, not it’s parent.

part1.Touched:Connect(function(hit)
		if hit== part2 then
			print('part1 has touched to part2')
		else
			print('they have not touched yet')
		end
	end)
1 Like

The wrong part of the code was this:

I need to be able to check if part1 has touched part2.

This won’t work because you need to have part1 be an actual part.

-- Check if two parts have touched

local part1 = script.Parent.Part1
local part2 = script.Parent.Part2

part1.Touched:Connect(function(hit2)
	if hit2.Parent == part2 then
		print('part1 has touched to part2')
	else
		print('they have not touched yet')
	end
end)
1 Like

Oh God! It cost me a lot, thank you very much, this worked! :smiley:

1 Like

Thank you so much guys :smiley: :smiley: nwn

No worry my man, if you need any help ping me on any Scripting Support topic :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.