Script cant actually find two different parts within an acceptable distance from each other

I’m making a map generation script and I want this portion of the script to change any required AttachmentPoints into DoorNodes (both are simply Parts that have been named this way) by checking if pairs of AttachmentPoints are close enough together in order to change them to DoorNodes

The issue is that while the script has no problem finding pairs of AttachmentPoints that are actually both the same part, it can’t find pairs of AttachmentPoints that are two DIFFERENT parts that are close enough together.

I’ve tried making the script less strict, printing anything the script DOES find to the console, i’ve searched for this problem and even asked the AI assistant for help and have come up with no solutions other than this junk piece of code.

function module.UpdateNodes(Room: Model)
	-- Find all attachment objects in the room
	local Attachments = {}
	for i, v in pairs(Room:GetDescendants()) do
		if string.find(v.Name, "AttachmentPoint", 1, true) or v.Name == "RoomAnchor" then
			table.insert(Attachments, v)
		end
	end
	-- for each attachment, check if any other attachments that arent descended from the same room are within a tolerance of it's position
	for i, v in pairs(Attachments) do
		for j, k in pairs(Attachments) do
			if v.Parent ~= k.Parent and (v.Position - k.Position).Magnitude <= 0.1 then
				-- if so, rename both to "DoorNode" and color them red (1,0,0)
				v.Name = "DoorNode"
				v.Color = Color3.new(1,0,0)
				k.Name = "DoorNode"
				k.Color = Color3.new(1,0,0)
				print(v)
				print(k)
			end
		end
	end
end

Nevermind, i forgot to make a second table that stores ALL attachmentobjects in the game, not just the ones in the current room

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