Block delete on hit

I have a block that I need to be destroyed on hit with another block. here is the script I have

local partToHit = game.workspace.DeletePoints.DeleteBlock1

script.Parent.Touched:Connect(function(hit)
	if hit == partToHit then
		print("Hit!")
		script.Parent:Destroy()
	end
end)

I see you have a print in there, is it printing? Where is the script not working?

there is no print, nor any errors. this is placed inside the block I want deleted

so it is never getting to the ‘print (“Hit!”)’ part?

Maybe have a print to see what is in ‘hit’

local partToHit = game.workspace.DeletePoints.DeleteBlock1
print("partToHit is ",partToHit)

script.Parent.Touched:Connect(function(hit)
	print("partToHit is ",partToHit)
	print("hit is ",hit)

	if hit == partToHit then
		print("Hit!")
		script.Parent:Destroy()
	end
end)

we are now printing “partToHit is” That’s it

can I see a screenshot of the output?

image

ok… so it is never detecting a hit.

no, it’s not, that’s why i am confused

Make sure you have cantouch set to true on the parts

it’s on, on both of the parts. smart tho

Do you have more than one item called DeleteBlock1 as a child of DeletePoints? If so you should change the if to check name and parent not the specific part.

local partToHit = game.workspace.DeletePoints.DeleteBlock1

script.Parent.Touched:Connect(function(hit)
	if hit.Name == “DeleteBlock1” and hit.Parent == game.Workspace.DeletePoints then
		print("Hit!")
		script.Parent:Destroy()
	end
end)

Can we see a screenshot of the hierarchy, what does DeletePoints look like, and what does the script.Parent look like in the explorer

image
image

So deleteblock1, will NOT be deleted, however if it touches script.Parent (the red block in the pic) that red block will be deleted, correct?

When does DeleteBlock1 ever come in contact with the red block?

Deleteblock 1 is the block that another block will touch to be deleted. I need script.parent to be deleted

Are both of the parts anchored? Because if so hit will not fire

Or, are you cframe moving the parts? That will also cause them to not collide.

yes Cframe, also both are anchored

XD double trouble. Yeah, you need to use another method to move it, and make sure it is unanchored