Get list other parts/attachment touching main attachment?

I need a way to get a list of parts or other attachments that overlap with the main attachment. I tried using :GetPartsInPart(), but it requires a BasePart (which attachments don’t fall under).

Anything helps, thanks

I don’t think this is exactly possible, unless you create a temporary part at the same position as that attachment, and then use GetPartsInPart on that temp part. This will give you parts, but not attachments. Can I ask you what you’re trying to achieve? The idea of finding attachments that overlap inside an attachment seems very strange.

1 Like

You could try :GetTouchingParts() then iterate through the children of it to see if any attachments mathematically fall into the same bounds defined by the part’s Size and Position. Pretty complex maths, but definitely possible.

I have a random hallway generator, and currently, none of the hallways loop back in on themself. The only things stopping that are walls. I need to find what wall the attachment is touching so that I can remove it. (it’s a bit confusing)

Attachment Example:

local function getOverlappingParts(attachment)
  local parent = attachment.Parent
  local overlaps = {}
  for _, part in pairs(parent:GetDescendants()) do
    if part ~= attachment and part:IsA("BasePart") then
      if part.Bounds:Overlaps(attachment.Bounds) then
        table.insert(overlaps, part)
      end
    end
  end
  return overlaps
end

Actually thinking about the maths, not as hard as I thought.
You should just be able to pass your attachment and part (as objects) in as parameters of this function:

local function isAttachmentWithinBounds(attachment, part)
    local attachmentPosition = attachment.WorldPosition
    local partPosition = part.Position
    local relativePosition = attachmentPosition - partPosition
    local partSize = part.Size
    if math.abs(relativePosition.X) <= partSize.X / 2 and
        math.abs(relativePosition.Y) <= partSize.Y / 2 and
        math.abs(relativePosition.Z) <= partSize.Z / 2 then
        return true
    else
        return false
    end
end
1 Like

I’ll test that out real quick

don’t mind this

I made some very minor edits to this code

local function getOverlappingParts(attachment)
	local overlap
	for _, part in pairs(game.Workspace:GetDescendants()) do
		if part:IsA("BasePart") and part.Name == "Wall" then
			if part.Bounds:Overlaps(attachment.Bounds) then
				overlap = part
				break
			end
		end
	end
	return overlap
end

It throws an error saying
Bounds is not a valid member of Part

Pretty sure they’re using ChatGPT to write responses, the maths I put above should work, try that.

I also edited this code, just to loop through all of the parts named “Wall” in the game, but the function just returns nil

I think I’m gonna try a couple of different things. If none of them work, I have a backup plan

For anyone who (for some reason) wants to know: I used “GetPartBoundsInRadius” and just used the attachment position and a radius of 1.5 as parameters. It then returns a list of any BasePart with the name “Wall” that is in that radius.