Detecting specific parts with GetTouchingParts

Hello, I’m trying to detect parts with a DragDetector using :GetTouchingParts but I can’t figure out how to separate the parts that do have a DragDetector inside of it and ignore the ones that don’t. Here is what I’ve done so far

		for i,v in pairs(DestroyPart:GetTouchingParts()) do
			if v.DragDetector then return end
				local list = v
				list:Destroy()
		end

Hello, I believe I have fulfilled your request.

for i, v in pairs(DestroyPart:GetTouchingParts()) do
    if v.DragDetector then
        -- perform actions here
        local list = v
        list:Destroy()
    end
end

You can use an if statement to check if the part has a DragDetector before performing any actions on it.

1 Like

It keeps checking for parts that don’t have a DragDetector inside of them, making and error and not completing the rest of the script.

1 Like

Try this instead:

for i, v in pairs(DestroyPart:GetTouchingParts()) do
    if v:FindFirstChild("DragDetector") then -- this way, if it doesn't have it, it would just skip onto the next part
        -- do whatever you need here
        local list = v
        list:Destroy()
    end
end
2 Likes

Oh I’m sorry about that. Try this:

for i, v in pairs(DestroyPart:GetTouchingParts()) do
    if not v.DragDetector then
        -- part doesn't have a DragDetector, skip to the next
        continue
    end
    
    -- part has a DragDetector, perform actions here
    local list = v
    list:Destroy()
end
1 Like

:gettouchingparts is currently broken or atleast it doesnt work right. I suggest using a script that uses .touched to each of the parts and sending it to a signal.

you can make a script to insert these script into the parts.

hope this helps!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.