neither worked
the first one is off by 90 degress and adding or subtracting 90 just makes it stay facing forward and the second one kept it facing forward
Alright one possible problem is that this heavily depends on how you rigged your turret base.
The calculations assume this that the base initially has the same CFrame as the top one
It will be different if the base is rotated, where the yaw angle becomes the pitch angle as the axises become different according to CFrame math since it’s relative to base so the head in this case is rotated 90 degrees in the Z axis and will cause errors.
The reason why I gave you the code bit taken from ThanksRoBama code:
Perhaps Sleitnicks method is better because you can choose the vectors from which you want to measure the angle:
-- rotateOrigin is now the gunBase (the big block connecting the barrel)
local targetPosition = mouse.Hit.Position
local turretPosition = rotateOrigin.Position
local turretLookVector = rotateOrigin.CFrame.LookVector -- this is facing the barrel
local targetLookVector = (targetPosition - turretPosition).Unit
local axis = Vector3.new(0, 1, 0)
local angle = AngleBetweenSigned(turretLookVector, targetLookVector, axis)
turretBase.TargetAngle = math.deg(angle)