How do I detect if part touches another part

@Azerty_103, note that when reading this article (that is for .Changed event) you can see that trying to get an event based on the Position doesn’t work.

It is the same than Basepart:GetPropertyChangedSignal("Position") :x
(According to this topic that talk about it)

EDIT: This is not what you intend to relay but it is just a fact that may serve this topic. I am aware that you don’t want the user to use this method but another one.

1 Like

I thought that work with Position. I tried with Value and it worked.

Well, I tested a script with a function bound on what you wrote, but it only fired when I was moving the part using MoveTool from Roblox Studio. When the part moves by itself (unanchored, …) it was not firing at all

After all, I may have not really understood the thing because yea :x

EDIT: This event only works when manually (with script or else) changing the position of the part.

@9c_Aw The script I gave you worked for me, I don’t know why it’s not working for you. You put the script inside of the part that destroy’s other parts?

sorry for the late response I just woke up today I’ll be testing the scripts

yes I put it in the part that destroys other part

the part it touches

I wanted YellowPart (the player controlling with gui buttons, It doesn’t have any relations to the player) whenever it touches other parts it will be destroyed

So, if the positions are all equal in the first place [ As in you are moving them all in the same increments, and were placed in same increments. So the position should end up equaling out with the other part’s position. ] - why not do something along the lives of:

local partA = game.Workspace:WaitForChild("parta",10)
local partB = game.Workspace:WaitForChild("partb",10)

if partA.Position == partB.Position then
--- code

end

I also tested this in studio with an unanchored part and it worked fine (deleting the part that the script is located within)

local debunk = false
local parta = script.Parent
local partb = game.Workspace:WaitForChild("partb",15)

parta.Touched:connect(function(hit)
	if debunk ==  false then
		debunk = true
		print("hit")
		print(hit)
		if hit == partb then
			print("ispart")
			parta:Destroy()
			print("destroyed")
		end
		debunk = false
	end
end)

There is also this option, if the part containing script is destroying other parts:

local debunk = false
local parta = script.Parent
local destroyablepart = game.Workspace:WaitForChild("destroyablepart",15)

parta.Touched:connect(function(hit)
	if debunk ==  false then
		debunk = true
		print("hit")
		print(hit)
		if hit.Name == "destroyablepart" then
			hit:Destroy()
		end
		debunk = false
	end
end)

So you would just title whichever parts you wish to be destroyable as “destroyablepart”

and then you can cause some “snow plow” type mayhem such as this:

(Sorry for the pets and random accessories - this is my development team’s testing game for accessories and other quirky features we are working on for our game currently, haha.

Hope this helps somehow !?

1 Like

Thanks for the scripts but sadly it didn’t work for me

Scripts 1 (The position script u replied)
I also tried that but it did nothing
I tried your script but it failed I also check the output for errors just incase
there were no errors

Script 2 (with the debunk)
the printing did work
it print who hit the part and prints when the part is being touched
I tried it with the other part (The part i wanted to destroy) it did not print
when it’s being touched and also did not print who touched it

Script 3 (detecting the specific part by detecting it’s name)
It did not work for the part but it did not delete the players body parts

I think the only solution for this one it making the part movement smooth
just like StrongBigeMan9 said sadly i dont know on how to make the part smooth
cuz i just added the position here is the one of the script for the moving part
just to let you know

local part = game.Workspace.Part
local button = script.Parent

button.MouseButton1Click:Connect(function()
	part.Position = part.Position + Vector3.new(0,0,1)
end)

--down V movement
1 Like

Yeah like @StrongBigeMan9 the touched event won’t fire for your case because you are manually changing the position and because of this there is no physics involved as the physics engine doesn’t do anything as it’s anchored and so the Touched event won’t fire.

This also means that at least one of the parts involved must not be BasePart.Anchored at the time of the collision.

In your case both parts are anchored I believed so the touched event will not occur.

Consequently, I recommend using region3 instead to detect the part for your pacman game scenario as it doesn’t rely on physics. This region3 tutorial by the DevKing should help you start out with how to use it.

Otherwise if you want to smoothen the part Position and use physics to move the part in order to make the Touched event work there is the BodyPosition | Documentation - Roblox Creator Hub bodymover. But I believe you want the parts to be anchored so yeah go for the region3.

7 Likes

Honestly You could just detect if the part is in a certain position(where the smaller white cube is) with a boolean statement.

I don’t want something complex i just want a simple part touches another part script.
For example BasePart only