Simple way to detect a touch between anchored parts

Basically I just need to know how to detect when two anchored parts touch. they do go inside of each other a little bit to if that helps.

script that moves part

local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAdded:Wait()
local mouse = player:GetMouse()
local storage = game:GetService("ReplicatedStorage")
local org = storage:WaitForChild("Thingthatfollowsmouse")
local debounce = false



script.Parent.MouseButton1Down:Connect(function()
	if debounce == false then
		debounce = true
		local copy = org:Clone()
		copy.Parent = workspace	
		mouse.TargetFilter = copy
		while true and wait() do
			local getpos = mouse.Hit.p
			local function thing()
				copy:SetPrimaryPartCFrame(CFrame.new(getpos) + Vector3.new(0, 0.5, 0))
			end
			thing()
		end
		
	end
end)

touch script in other part

script.Parent.Touched:Connect(function(hit)
	print(hit)
end)

Please help <3

You can use this function :link: every time your interacted part moves. I hope the example localscript below can help:

local Mouse = LocalPlayer:GetMouse( )
local BlackListFolder = workspace:WaitForChild("BlackListFolder")
local MovingPart = BlackListFolder:WaitForChild( "MovingPart" ) 

Mouse.TargetFilter = BlackListFolder

local function MoveAndDetect( )
	local MousePos = Mouse.Hit.p
	local Offset = Vector3.new(0, MovingPart.Size.Y/2, 0)
	MovingPart.Position =  MousePos + Offset
	local TouchingParts = MovingPart:GetTouchingParts() --Gets intersecting parts
 	if #TouchingParts > 0 then print( TouchingParts ) end --Prevents printing an empty table
end

Mouse.Button1Down:Connect( MoveAndDetect )
--Will not replicate
1 Like

I have no idea why I didn’t think of this, thank you so much man!

1 Like
script.Parent.Touched:Connect(function(hit)
	if hit.Name == "" then --name of the other part (make it unique so unwanted parts dont cause the event to fire)
		--do code
	end
end)

This is fairly simple, just give the part being touched (which causes the “Touched” event to fire) a unique name and then check if the part being touched is that particular part by comparing the value of the “Name” property for each part (the touching part which caused the “Touched” event to fire and the name of the expected part you want to cause the “Touched” event to fire).

Sorry for necroposting, but .Touched will not work for anchored parts sadly.