Welding multiple parts to one part using a script

  1. What do you want to achieve?
    I’m currently making a hood system that welds a model to your head, the method im currently using involves manually welding parts to the MainPart of the model using a plugin

    I was wondering if I could do that automatically from a script

  2. What is the issue?
    I tried to weld the parts from a script in server script service but it didnt turn out well, the parts change their cframe regardless of what i try to do


Should look like:
Should Be

How it turned out:
How It Turned Out
3. What solutions have you tried so far?
I tried using the C0 property but it still did not fix it and I tried putting the part inside of the main part

for i, v in pairs(game.ServerStorage.Hoods:GetDescendants()) do
	if v:IsA("BasePart") then
		if v.Name == "MainPart" then
			for x,z in pairs(v:GetChildren()) do
				if not z:IsA("SpecialMesh") then
					local weld = Instance.new("Weld")
					z.CFrame = v.CFrame
					weld.Part0 = v
					weld.Part1 = z
					weld.C0 = z.CFrame:Inverse() * v.CFrame
					weld.Parent = z

Here’s how everying is layed out:

You could try using this script:

for i, v in next, Hat:GetChildren() do
	if v ~= Hat.PrimaryPart then
		local Weld = Instance.new("Weld")
		Weld.Part0 = v
		Weld.Part1 = Hat.PriamryPart
	    Weld.C0 = v.CFrame:inverse()
		Weld.C1 = Hat.PrimaryPart.CFrame:inverse()
        Weld.Parent = Hat.PrimaryPart

The hat must have a PrimaryPart though.

EDIT: @Arcilios Are you trying to weld the hat to the head, or all the parts in the hat to the hat’s hitbox / primarypart?


Im trying to weld all the parts inside the model to the MainPart

1 Like

Is the MainPart the head, or something else?

The MainPart is a part thats shaped like the head inside of the hat model

Its not the character’s Head no

1 Like

In that case, use this:

Remember… the hat should have a primarypart, and the primarypart should be the part that you want to weld all the parts to!

Have you tried using WeldConstraints? They won’t require a C1/C0, just a Part1/Part0. They’re far easier to use.

Wiki page

1 Like

wouldn’t using weldconstraint’s be much easier or would it not work with this?

If you can, here’s a script that might work. (sorry for my bad coding lol)

local descendants = script.Parent:GetDescendants()
for index, descendant in pairs(descendants) do
	if descendant.ClassName == "Script" then
		local weld = Instance.new("WeldConstraint", descendant)
		weld.Part0 = descendant
		weld.Part1 = script.Parent.PrimaryPart