Script is changing object orientation

so i tried to make that gun would turn up and down and i ran into a problem that my script is changing meshparts orientation maybe because of incorrect hinge
image


gunControlEvent.OnServerEvent:Connect(function(player, ms)
	local YAngle = math.asin(ms.Y)
	warn((end3.CFrame * CFrame.Angles(YAngle, 0, 0)) * CFrame.new(0, 0, gunPart.Size.Z / 2))
	gunPart.CFrame = (end3.CFrame * CFrame.Angles(YAngle, 0, 0)) * CFrame.new(0, 0, gunPart.Size.Z / 2)
end)

If you are using the HingeConstraint in Servo mode, then you can just set the new angle when you want it move move. I use that method for opening doors with hinges.