How can I make these parts auto-weld?

as i would think that would happpen,anchoring is the best soltuion or you can write around 100 lines of code for constraints

local function WeldModel(ModelInstance)
	local PrimaryPart = ModelInstance.PrimaryPart
	
	for i,v in pairs(ModelInstance:GetDescendants()) do
		if v:IsA("BasePart") then
			PrimaryPart = PrimaryPart or v
			
			if v:FindFirstChildOfClass("Weld") then
				v.Weld:Destroy()
			end
			
			local Weld = Instance.new("Weld")
			Weld.Part0 = PrimaryPart
			Weld.Part1 = v
			Weld.C0 = PrimaryPart.CFrame:Inverse() * v.CFrame
			Weld.Parent = v
		end
	end	
end

Run in the command bar with the desired model to weld as the only argument. This was quickly setup without any testing, so theres a small chance that somethings wrong. I suggest creating a model for the parts, the first part to be placed becomes the primarypart. When you add more parts you just weld them together using the function i provided.

5 Likes

The point is; There are 1000s of different ways to go about doing this. A ton of people have posted great solutions; I suggest picking the one that seems the easiest to understand and works the best for you.

1 Like

im confused,this prob wont work since it happens when game starts

The goal is not to weld the entire structure together; Please read the OP fully. The goal is to weld parts that are placed on each other or near to each other together, so that it creates a cool effect when the building is exploded or one part is removed.

Well, I wish I had just realised that I could’ve just done Part:MakeJoints(), because that works much better. With the weld they keep glitching around when you start to make complex structures.

1 Like