How do i make a part detection script (read desc)

how do i make a script that tells when a part touched another part and it will detect the part.
for example: the tools part touched the part on the ground and the script will make sure that the part that touched it is the tools part otherwise if its not then it won’t run the script.

here you can take this script and redo it if you want or you can add to it.

local clickdetector = script.Parent.ClickDetector

local goto = script.Parent.Parent.garbagegoto

local godown = script.Parent.Parent.garbagegoto2

local part = script.Parent.Parent.Union

local player = game.Players:FindFirstChild('Humanoid')

local tool1 = game.StarterPack.sweeper1

local toolP = tool1.Model

clickdetector.MouseClick:Connect(function(player)
	part.Position = godown.Position
	wait(5)
	part.Transparency = 0
	part.Position = goto.Position
end)

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

By using the Touched function, you can find out what specifically hit the part. I will just make the bottom bit.

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

 if hit.Name == tool1.Name then
--code here for what you want it to do

end
end)
3 Likes

Like @BabyHades_2 suggested, you can detect when a part is touching another part using a .Touched event.

whenever an object touches an object connected with this event, the event will trigger. By hooking this up with a function, you can run code whenever the event is triggered.

part.Touched:Connect(function(hit) -- "hit" is what's touching the object
    -- code here runs when the event is triggered
end)
1 Like