How do you destroy a part if a part touches another part?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want it so that when a certain part touches another part, it destroys that part.
  2. What is the issue? Include screenshots / videos if possible!
    I have a script, but whenever I test, it never destroys.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I put print statements but none printed.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
script.Parent.Touched:Connect(function(hit)
	print("hit")
	if hit.Parent:FindFirstChild("Part") then
		print("Is part")
		if hit.Parent.Name == "Fall" then
			print("Is fall part")
			hit.Parent:Destroy()
			print("Destroyed")
		end
	end
end)

This script looks fine by itself, assuming you placed it in a normal Script inside the part you want to be touched, and not a LocalScript or something. The problem is probably with the hierarchy of hit. What does the hierarchy of Fall look like?

Also

Not even the print("hit")?

try using :IsA(“BasePart”) instead if :FindFirstChild(“Part”)

It only prints “hit” if a player touches it.

And no it didn’t work unfortunately.

I think you could do something like this. You cant print “hit” because it hasnt been defined yet

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:WaitForChild("NameOfThePart") then
		print("I hit it:)
		if hit.Parent.Name == "NameofthePart" then
			print("IDonet")
			hit.Parent:Destroy()
			print("Destroyed")
		end
	end
end)
That should work.
script.Parent.Touched:Connect(function(h)
    local part = h.Parent
    if part:IsA("Part") and part.Name == "Fall" then
        part:Destroy()
    end
end)
1 Like

I’m having This Issue as well.