Is it possible to make a event fire when a part touches another part?

I’m working on a game and there is a cube but when it touches the wall It will be destroyed. But I only want it to be that one specific wall with a specific name.

Here is my code
local Part = game.Workspace.Cube
local Stoper = game.Workspace.End

Stoper.Touched:Connect(function()
Part:Destroy()
end)

Touched gives the other part to the connected functions.

Stoper.Touched:Connect(function(hit)
    if hit == Part then
        Part:Destroy()
    end
end)

I didn’t work, I just stopped and didn’t destroy.

Were there any errors in the output?

I would just do the .Touched event on the part that detects the touch. Then you pass Touched (or your own name for it) as a variable and then check if that variable is the same as the part you want, and if so do what you want! Hopes this helps!

try this code:

local Part = game.Workspace:WaitForChild("Cube")

local Stoper = game.Workspace:WaitForChild("End")

Stoper.Touched:Connect(function(hit)

if hit == Part then -- checks if the item is the part you want to delete.

Part:Destroy()

end

end)

There wasn’t any errors in the out put, it was just empty.

There are thousands upon thousands of posts and documentations about this problem.

Duplicate DevForum Post

BasePart Touched Event

Do your research before making a DevForum post.

try my new code. see if it works

It didn’t work, there were no errors either. Does the fact that the part is a union effect the code in any way as well?

Yeah I saw those forums but it didn’t really help.

Check if canCollide property is good. Also can I see when you start the game what happens?

robloxapp-20210717-1227030.wmv (1.7 MB)

thats the video As you can see it touches it but doesn’t work

What is stopper? What is the part?

local Part = game.Workspace:WaitForChild("Cube")

local Stoper = game.Workspace:WaitForChild("End")

Stoper.Touched:Connect(funcion(hit)
if hit.Name == "Cube" then
Part:Destroy()
end
end)

Stopper is the end part that you see moving, the invisible one.

Oh one thing, I have the script inside of the cube model its self is that a problem?