How do I detect if part touches another part

Soooo I have to add wait when the part moves it’s position?

A wait won’t solve if it’s being brought to its new position instantaneously – I edited my post as you replied with a potential solution if you’d like to maintain usage of Touched events.

It’s past 4AM for me atm, so I may need to continue helping later on, if needed.

here are the one of the scripts from the Up,Down buttons

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

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

but i don’t know where to add the wait()

thanks for helping see you tmrw

1 Like

If your script don’t work, it is probably because you used CFrame or Position change. I writed a script below. You will have to put this script on yellow part.

script.Parent:GetPropertyChangedSignal("Position"):Connect(function()
    for count, instance in ipairs(script.Parent:GetTouchingParts()) do
        if instance.Name == "WhitePart" then
            instance:Destroy()
        end
    end
end)

The name of lthe ittle white part must be “WhitePart”

1 Like

I tried your script and i also parent it to the part the one who changes position
but sadly it did not work i checked the output there are no errors
i think the only solution is to make the moving to be smooth
but i dont know how to do it

Do you renamed the white part ?

yes I did rename the part to WhitePart

Try this, put this script in the part that you want to destroy the other parts. This will work even if the part has can collide off.

local part = script.Parent

local function GetTouchingParts(thepart)
   local connection = thepart.Touched:Connect(function() end)
   local results = thepart:GetTouchingParts()
   connection:Disconnect()
   return results
end


while wait() do
   for I, v in pairs(GetTouchingParts(part)) do
     v:Destroy()
   end
end
script.Parent:GetPropertyChangedSignal("Position"):Connect(function()
    print(1)
    for count, instance in ipairs(script.Parent:GetTouchingParts()) do
        if instance.Name == "WhitePart" then
            print(2)
            instance:Destroy()
        end
    end
    print(3)
end)

What number is printes on this script when you move the yellow part at the same position than the white part?

I check the output there are no prints

Did you try my script, it should work.

where should i parent the script? just wanna know

The script should be a child of the main part. Like if the script was in PartA, whatever touched PartA will be destroyed.

it did not work :frowning:
no errors also

Oh strange, I’m in class right now so I can’t test it but I can test it later.

sorry for interrupting with your classes you should do your class first

2 Likes

I think you may try something related to the WorldRoot (the mosed used one is Workspace).

A function called :ArePartsTouchingOthers() does exist, and may help you in what you intend to do !

You may check this post to have further pieces of information about it, how to use it, …

It seems that it returs a boolean that says if a part is touching one or other specific parts (not in the table).

They say:

Return: Boolean. → True if any of the parts in partList [table containing parts] are touching any other parts (parts not in the partList). False if no parts are passed.

It can be an efficient way, combined with .Touched event !

Replace “script.Parent:GetPropertyChangedSignal(“Position”)” In first line of my script by Event who make move the yellow part.

script.Parent:GetPropertyChangedSignal("Position"):Connect(function()
    for count, instance in ipairs(script.Parent:GetTouchingParts()) do
        if instance.Name == "WhitePart" then
            instance:Destroy()
        end
    end
end)

Apologies, but when script.Parent hits a part, do you want script.Parent to be destroyed, or the part it touches?