Help fixing artificial horizon

I need help fixing my artificial horizon for my plane, I want to achieve making a functioning A.H. like the one in real life and the one in Project Flight’s Boeing 737 pfd. It’s what I want to achieve but with my artificial horizon.

video for example in PF:

Here’s what happens to mine:


pitch and roll work, but when yawing (i think) the artificial horizon begin to move in way’s I don’t want it to. (towards the end of the video)

I’ve looked through a few dev forum posts but I was unsuccessful in finding solutions. I don’t know why it is moving like this when I moved it around. I’ve had a friend who rescripted parts of my code, but it still shows the same problem.

Code:

local Folder = script.Parent

task.spawn(function()
	while task.wait() do
		local o = Vector3.new(math.clamp(Folder.Parent.plane.Orientation.X,-45,45),0,Folder.Parent.plane.Orientation.Z)

		Folder.AnilogArtificialHorizon.GyroSpheretest:PivotTo(
			CFrame.new(Folder.AnilogArtificialHorizon.GyroSpheretest.PrimaryPart.Position) * 
				CFrame.Angles(math.rad(o.X),math.rad(o.Y),math.rad(o.Z))
		)
	end
end)

Sorry if you don’t really understand what I’m trying to say, I’m horrible at explaining things.