Trouble With Welding Gun Magazine to Hand

I’m trying to weld a gun magazine to the player’s left hand during an animation, it works, however, the position of the mag changes depending on the direction the player is standing in. How can I fix this?

This is the issue:

This is the code I’m using:

ReloadAnim:GetMarkerReachedSignal("MagGrab"):Connect(function()
	TempMag = Mag:Clone()
	local MagWeld = Instance.new("WeldConstraint")
	MagWeld.Parent = TempMag
	if Character:FindFirstChild("LeftHand") then
		MagWeld.Part0 = Character:FindFirstChild("LeftHand")
		MagWeld.Part1 = TempMag
		TempMag.CFrame = CFrame.new(Character:FindFirstChild("LeftHand").Position) * CFrame.new(0.2, 0, 0.1) * CFrame.Angles(0, math.rad(-90), 0)
	else
		TempMag:Destroy()
	end
	TempMag.Parent = workspace
end)

This is the first time I’ve made a scripting support post, so if I made any mistakes, please let me know!

CFrame.new(Character:FindFirstChild("LeftHand").Position) is a CFrame with an empty rotation. Do this:

TempMag.CFrame = Character:FindFirstChild("LeftHand").CFrame * CFrame.new(0.2, 0, 0.1) * CFrame.Angles(0, -math.pi/2, 0) -- learn radians btw

1 Like

What is the difference between using math.rad() and math.pi?

math.rad() converts degrees to radians, math.pi returns the value of pie (22/7 or approximately 3.14).
You can read more here.

1 Like

It’s just unnecessary processing the game has to do. It’s small but it’s a good habit. Why tell the game to calculate how much 90° is in radians when you already know the answer is math.pi / 2? Just to clarify math.rad(-90) will return you -math.pi / 2. So you can just replace it.

1 Like