Equipping tools glitches player jump direction

I am making a 3rd person view part for my gun game by welding a weapon to player’s right hand. However, it makes the player’s jumping direction sideways everytime I go upper left, upper right and backward.

Before equipping:
robloxapp-20230416-1721576.wmv (1.7 MB)

After equipping:
robloxapp-20230416-1723277.wmv (2.3 MB)

My movement code (I’m replicating Quake movement):

local player = game:GetService('Players').LocalPlayer
local run = game:GetService('RunService')
local UIS = game:GetService('UserInputService')

local character = player.Character
local rootpart = character.PrimaryPart
local humanoid = character['Humanoid']

local jumping = false

run.RenderStepped:Connect(function()
	if UIS:IsKeyDown(Enum.KeyCode.LeftShift) and not crouching and not climbing then
		walkSpeed = 20
	else
        walkSpeed = 12
	end
	humanoid.WalkSpeed = walkSpeed
	if jumping then
		humanoid.WalkSpeed = 20
		humanoid:Move(Vector3.new(rootpart.Velocity.X / humanoid.WalkSpeed, 0, rootpart.Velocity.Z / humanoid.WalkSpeed), false)
	end
end)

aimEnable.Event:Connect(function(aim)
	aiming = aim
end)

humanoid.StateChanged:Connect(function(old, new)
	if new == Enum.HumanoidStateType.Jumping or new == Enum.HumanoidStateType.Freefall then
		jumping = true
	else
		jumping = false
	end
end)

Gun equipping:

local storage = game:GetService('ReplicatedStorage')
local weaponWeld = storage.Event.Global['WeaponWeld']

weaponWeld.OnServerEvent:Connect(function(player, hand, weapon)
	--Delete pre-exisitng weapons if any
    for _, v in pairs(player.Character:GetChildren()) do
		if v:IsA('Model') or v.Name == 'Motor6D' then
			v:Destroy()
		end
	end
	
    --Attaching weapon into player's hand
	local model = storage.Weapon.Models:FindFirstChild(weapon):Clone()
	
	local weld = Instance.new('Motor6D')
	weld.Parent = model:FindFirstChild('Handle')
	weld.Part0 = player.Character.RightHand
	weld.Part1 = model:FindFirstChild('Handle')
	model.Parent = player.Character
	
	for _, v in pairs(model:GetChildren()) do
		if v:IsA('BasePart') or v:IsA('MeshPart') then
			v.CanCollide = false
			v.Massless = true
			v.CustomPhysicalProperties = PhysicalProperties.new(0,0,0,0,0)
		end
	end
end)

I have double checked every part of the weapon and all of them are unanchored, non-collidable, massless and had all physical properties set to 0. How can I fix it?