Help With Understanding If a Vector3 Is Inside One Of the Parts In a Table?

Hello Devforum members! I’m trying to cover certain region with attachments(points) without them being inside the parts in the region. Something like this


The issue is that I dont understand why/how to achieve it and it ends up like that or

i was looking on the Developer hub,Scriptinghelpers and this site if there is any way to detect if a Vector3(Not part) is inside a table of Region3s or parts however that failed. I have uploaded the script incase anyone can understand where i did wrong and help me


function IsInRegion(position,brick) -- Defines if a position is inside a brick
	local UpperX = brick.Position.X + brick.Size.X/2
	local LowerX = brick.Position.X - brick.Size.X/2
	local UpperY = brick.Position.Y + brick.Size.Y/2
	local LowerY = brick.Position.Y - brick.Size.Y/2
	local UpperZ = brick.Position.Z + brick.Size.Z/2
	local LowerZ = brick.Position.Z - brick.Size.Z/2
	if position.X < math.max(LowerX,UpperX) and position.X > math.min(LowerX,UpperX) and position.Y < math.max(LowerY,UpperY) and position.Y > math.min(LowerY,UpperY) and position.Z < math.max(LowerZ,UpperZ) and position.Z > math.min(LowerZ,UpperZ) then
		return true
	
	end
	if position.X > math.max(LowerX,UpperX) and position.X < math.min(LowerX,UpperX) and position.Y > math.max(LowerY,UpperY) and position.Y < math.min(LowerY,UpperY) and position.Z > math.max(LowerZ,UpperZ) and position.Z < math.min(LowerZ,UpperZ) then
		return false
	end
end

for i,part in ipairs(workspace.Folder:GetChildren()) do -- the parts are inside a Folder
	for i,anotherPart in ipairs(workspace.Folder:GetChildren()) do
		if anotherPart ~= part then
			for x = 0,anotherPart.Size.X,2 do
				for z = 0,anotherPart.Size.Z,2 do
					local point = Vector3.new(anotherPart.Position.X- anotherPart.Size.X/2+x,anotherPart.Position.Y+anotherPart.Size.Y/2+4,anotherPart.Position.Z-anotherPart.Size.Z/2+z)
					if not(IsInRegion(point,part) == true ) then
						local att = Instance.new("Attachment",anotherPart)
						att.WorldPosition = point
						att.Visible = true
					end

				end
			end
		end
	end

end

Any suggestions? Where did i go wrong?