Welding a Weapon to a Character Rotation Problems

Hi! I’m trying to weld a sword to a character’s left leg using the following script.

local function replicatedWeapon(c)
	local replicatedsword = game.ReplicatedStorage.Replicas["Katana"]:Clone()
	local handle = replicatedsword.Handle
	local rp = c.HumanoidRootPart
	
	local weld = Instance.new("Weld")
	weld.Part0 = rp
	weld.Part1 = handle
	weld.C1 = CFrame.new(0.6, 1.2, -1.1) * CFrame.Angles(math.rad(-10),math.rad(90),math.rad(0))
	
	weld.Parent = handle
	replicatedsword.Parent = rp
	
end

local function removeWeapon(c)
	local sword = c:FindFirstChild("Katana Replica")
	
	if sword then
		sword:Destroy()
	end
end

game.Players.PlayerAdded:Connect(function(p)
	p.CharacterAdded:Connect(function(c)
		local weapon = p.Backpack:FindFirstChild("Katana")
		
		if weapon then
			replicatedWeapon(c)
		end
		
		p.Backpack.ChildAdded:Connect(function(s)
			if s.Name == "Katana" then
				replicatedWeapon(c)
			end
		end)
		
		p.Backpack.ChildRemoved:Connect(function(s)
			if s.Name == "Katana" then
				removeWeapon(c)
			end
		end)
	end)
end)

Unfortunately, the weld.C1 orientation does not copy to the character properly.

How I want it:

The rotation issue:
image

1 Like

I would recommend using WeldConstraints over Welds. They are, in my opinion, the less complex version of Welds and they achieve the same thing. The creator hub even describes them as a newer alternative for those who don’t want to manually set the C0 and C1 properties.

1 Like

Working with CFrame.Angles can be kind of hard, because the rotations are not composed in the same order as what you get if you put numbers into CFrame Orientation in the property panel. Angles does Tait-Bryan XYZ, CFrame.fromOrientation(x,y,z) does YXZ. From your screenshot, it does look like you want a 90 deg Y rotation then 10 deg X, and that’s not what CFrame.Angles is going to do. I would say just try using CFrame.fromOrientation as your first step. If it’s still wrong, it’s possibly a direction issue. Weld.C1 is harder to think about than C0 , because it’s the offset of the HRP from the sword, which is not how one naturally things about things (it’s the inverse).

I would recommend using some code in the command bar to achieve a relative object space offset to your desire without doing it yourself.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.