Issue with Tweening CFrame - Global Rotation when needing Local

Hello, I am working on a mounted gun on one of my small boats.

This is an idea of how the welding is setup:

local tempWeld = Instance.new("Weld")
tempWeld.Parent = script.Parent.Parent.target
tempWeld.Part0 = script.Parent.Parent.target
tempWeld.Part1 = script.Parent.offset

local weldToBoat = Instance.new("Weld")
weldToBoat.Parent = script.Parent.Parent.Parent.ShipStructure.Parts.Model.TurrentLock.lock
weldToBoat.Part0 = weldToBoat.Parent
weldToBoat.Part1 = script.Parent.Parent.target

Below is the function that is called as W/A/S/D is being held down:

local tweenGoal = {}
local tween = nil
local init = true
function Turrent:Traverse(dir)
	if init then
		init = false
		tweenGoal.C0 = self.Weld.C1 * CFrame.fromEulerAnglesXYZ(0, 0, 0)
	end
	if self.Boat.Alive == false then return end
	
	if dir == "Up" then
		tweenGoal.C0 = tweenGoal.C0 * CFrame.fromEulerAnglesXYZ(math.rad(2), 0, 0)
	elseif dir == "Down" then
		tweenGoal.C0 = tweenGoal.C0 * CFrame.fromEulerAnglesXYZ(math.rad(-2), 0, 0)
	elseif dir == "Right" then
		tweenGoal.C0 = tweenGoal.C0 * CFrame.fromEulerAnglesXYZ(0, math.rad(-2), 0)
	elseif dir == "Left" then
		tweenGoal.C0 = tweenGoal.C0 * CFrame.fromEulerAnglesXYZ(0, math.rad(2), 0)
	end
	
	
	local x, y, z = tweenGoal.C0:toEulerAnglesXYZ()
	x = math.clamp(x, math.rad(-10), math.rad(30))
	y = math.clamp(y, math.rad(-90), math.rad(90))
	tweenGoal.C0 = CFrame.new(tweenGoal.C0.X, tweenGoal.C0.Y, tweenGoal.C0.Z) * CFrame.fromEulerAnglesXYZ(x, y, 0)

	tween = TweenService:Create(self.Weld, self.tweenInfo, tweenGoal)
	tween:Play()

end

The issue is it appears to be rotating globally:
db413d3ca524713a7e63c072a72a16f0

How can I fix this so that it does not rotate on what appears to be the Z axis? Also, if anyone has a more efficient way of doing this, I am open to suggestions.

Tl;dr Pitch yaw and roll can be swapped around based on the rotation of part0 and part1, Create new parts for Part0 and Part1 with the same rotation to be welded together, or just make the two parts the same default rotation(up vector up look vector forwards, right vector right)

When welding items, the rotation of the two objects being welded affect how things are handled. It can turn from pitch,yaw,roll to something like yaw,roll,pitch and be completely out of whack. You can either try to guess which combination of pitch yaw and roll it is by testing it, or just create two other correctly and samely rotated parts for the Part0 and Part1 of the weld

1 Like