How to make a part detect when it hits a specific part?

I am trying to detect when “game.Workspace.Meteor1.ImportantPart” touches “game.Workspace.Baseplate

I’ve tried:

local met = game.Workspace.Meteor1

met.ImportantPart.Touched:Connection(function(Hit)
	met.ImportantPart.Anchored = true
end)

But, I get this error:
Connection is not a valid member of RBXScriptSignal

1 Like

“Connection” is not the correct way to connect a function, and it’s not a function of RBXScriptSignal. Instead, use “Connect”.

local met = game.Workspace.Meteor1

met.ImportantPart.Touched:Connect(function(Hit)
	met.ImportantPart.Anchored = true
end)

The script doesn’t detect when the specific part touches a specific part, it only detects when the part is touched. To fix this, try this:

local met = game.Workspace.Meteor1
local targetPart = game.Workspace.Baseplate

met.ImportantPart.Touched:Connect(function(Hit)
    if Hit == targetPart then
 	    met.ImportantPart.Anchored = true
    end
end)
4 Likes

Try this:

local met = game.Workspace.Meteor1

met.ImportantPart.Touched:Connection(function(Hit)
if Hit.Name == “BasePlate” then
met.ImportantPart.Anchored = true
end)

You could cast a ray using raycasting on the part and detect when the ray hits another object. This is better than .Touched.