Weld changes part position

I’ve been making a portion of code inside my weld script where if I unequip my tool it would then clone all the parts, parent them to a model and then welding them together. I’ve gotten to the point where the parts are where I want it to be, but all the parts are just in a mess.

This is what I want it to look like:

This is what I have achieved so far:
now

I’ve looked through dev forum for a bit and I’ve also read the API reference on CFrame but I still don’t really understand. (I’ve always used WeldContraints in stuff like these so I don’t go insane making a weld script.)

This is what the portion of code that I’m working on looks like as of right now:

script.Parent.Unequipped:Connect(function()
	local Torso = script.Parent.Parent.Parent.Character.Torso
	Model = Instance.new("Model", Torso)
	
	for _, v in pairs(script.Parent:GetChildren()) do
		if v:IsA("UnionOperation") or v:IsA("Part") or v:IsA("BasePart") or v:IsA("MeshPart") then
			local Cloned = v:Clone()
			Cloned.Parent = Model
			
			local Weld = Instance.new("Weld", Torso)
			
			Weld.Part0 = Torso
			Weld.Part1 = Cloned
			Weld.C1 = Cloned.CFrame:ToObjectSpace(Cloned.CFrame * CFrame.new(0, 0, 1))
		end
	end
end)

Any sort of help would be greatly appreciated since I will most likely be working on more things that involve welds and a solution to this would probably make me understand a bit more about CFrame and welds.

2 Likes

You would simply change

Weld.C1 = Cloned.CFrame:ToObjectSpace(Cloned.CFrame * CFrame.new(0, 0, 1))

To

Weld.C1 = Cloned.CFrame:ToObjectSpace(Torso.CFrame * CFrame.new(0, 0, 1))

Thanks for the reply but the parts are still in weird positions when welded. I’ve examined the parts a bit more and I think most of them have the wrong rotation as well as being in the wrong position.

What the gun looks like when it is unequipped with the edit:

Also I didn’t mention that I currently want it to look like this and I’ll work on the angle of all the parts later:

This is what the model looks like in the explorer if that helps (the gun is all CSG):
explorer

These conditions are unnecessary. All of these fall under the BasePart category.

1 Like

Okay, I’ll change that now. Thanks for the feedback, I’m still waiting for a solution about the welding though.

I ended asking a friend where he came up with the solution of having a model with a cloned HumanoidRootPart with the gun model welded to it, and then weld the cloned HumanoidRootPart to the player’s actual HumanoidRootPart (I welded it to the Torso so the gun model moves with the idle animation).