How do I make an instance between every part?

Lets say I have a for loop that makes 100 parts. How can I make a constraint between ALL of the parts? Each part has a constraint to EVERY other part.

I know this is a bit inefficient, but something like this could work?

local parts = {}

for i = 1, 100 do
	local part = Instance.new("Part")
	table.insert(parts, part)
end

for i,v in pairs(parts) do
	if not v:FindFirstChildOfClass("Attachment") then
		local a = Instance.new("Attachment")
		a.Parent = v
	end
	
	for i, v2 in parts(parts) do
		if v ~= v2 then
			if not v2:FindFirstChildOfClass("Attachment") then
				local a = Instance.new("Attachment")
				a.Parent = v2
			end
			
			local c1 = Instance.new("Constraint")
			local c2 = Instance.new("Constraint")
			c1.Attachment0 = v:FindFirstChildOfClass("Attachment")
			c1.Attachment1 = v2:FindFirstChildOfClass("Attachment")
			c2.Attachment0 = v2:FindFirstChildOfClass("Attachment")
			c2.Attachment1 = v:FindFirstChildOfClass("Attachment")
			
			c1.Parent = v
			c2.Parent = v2
		end
	end
end

Iā€™m pretty sure this may lag a bit, but this does what you asked for

1 Like