How to know if a part touches another part?

Im making a rythm game. Title says it all.

1 Like

Just search it up. There are wikis on the DevHub.
I really forgot lol

I did the searching for you, you’re welcome.

1 Like
BasePart:GetTouchingParts()

It returns a table of parts that it touches.

Well this would be a good use of the .Touched event.

You would use the event like so (also sorry im writing this code on mobile):

local partToBeTouched = script.Parent
local partToTouch = —Wherever the part that touches the other one will be located.

partToBeTouched.Touched:Connect(function(partHit)
if partHit == partToTouch then
—do what you want after it’s touched
end
end)

this might work:

local parent = script.Parent

parent.Touched:Connect(function(hit) -- if something touched the parent
	if hit:IsA("Part") then -- check if the it is a part
		print("touched a part!") -- output
	end
end)

Use the Touched event to handle Touch events.

local part = game.Workspace.MyPart
part.Touched:Connect(function(otherPart)
   --otherPart was the part that touched it
   otherPart.Transparency = 1
   --Here, we've turned any parts that touched our parts invisible
end)

Use the TouchEnded event to handle when parts stop touching.

part.TouchEnded:Connect(function(otherPart)
   --otherPart was the part that touched it
   otherPart.Transparency = 0
   --Here, we've turned any parts that finish touching visible again
end)

Additionally, you can use the GetTouchingParts() to return an array of parts currently touching it.

for i, touchingPart in pairs(part:GetTouchingParts()) do
    --Action here, on touchingPart
end