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: