Align orientation causing a weird flip all of da sudden

[my bad for the thing in the clip i forgot to unlock and im lazy ok]

yoo so this issue popped up after i built some parts of the map
heres the issue:

it just does a odd flip when i arrive there im not too sure why, everything was working properly before i built the map
heres the code:


	local mag = (rootpart.Position - targetRoot.Position).Magnitude

local attachmentTarget = Instance.new("Attachment")
attachmentTarget.CFrame = CFrame.new(0,0,2.5)
attachmentTarget.Parent = targetRoot
game.Debris:AddItem(attachmentTarget,.30)

local Attachment = Instance.new("Attachment")
Attachment.Parent = rootpart

local alignOrientation = Instance.new("AlignOrientation")
alignOrientation.Attachment0 = Attachment
alignOrientation.Mode = Enum.OrientationAlignmentMode.OneAttachment
alignOrientation.MaxTorque = math.huge
alignOrientation.Responsiveness = 2000
alignOrientation.Parent = rootpart
game.Debris:AddItem(alignOrientation,.30)

local responsiveness = 100 - math.ceil(mag / 10) * 10 + 50

local alignPosition = Instance.new("AlignPosition",rootpart)
alignPosition.Attachment0 = Attachment
alignPosition.Mode = Enum.PositionAlignmentMode.OneAttachment
alignPosition.MaxForce = math.huge
alignPosition.Responsiveness = responsiveness

game.Debris:AddItem(alignPosition, .30)

grabConnection =  runService.Heartbeat:Connect(function() 
	alignOrientation.CFrame = CFrame.new(rootpart.Position,targetRoot.Position)
	alignPosition.Position =  attachmentTarget.WorldPosition	 --targetRoot.Position
end)

local t = (mag<50) and .10 or .25

task.wait(t)

grabConnection:Disconnect()
grabConnection = nil

alignOrientation.CFrame = targetRoot.CFrame



if serverfunctions:exists(target) and serverfunctions:exists(char) then
	local info = styleLibrary["Dishonored Assasin"]({Char = char,plr = plr,Target = target,things  = {ability = ability}})
	serverfunctions.dmg(char,target,info)
end

some things i excluded:

–math.huge properties have nothing to do with the issue

–responsiveness number has nothing to do with the issue (tried on various distances with the math.ceil calculation)

– there is no animation that does any kind of a flip

– the custom avatar has nothing to do with it, tried on various avatars

i was reworking some code lately and must’ve touched something on accident, i’ve re-read but cant spot the issue, let me know if you got anything

nevermind fixed it

swapped

alignOrientation.CFrame = targetRoot.CFrame

to

alignOrientation.CFrame = CFrame.lookAt(rootpart.Position,Vector3.new(targetRoot.Position.X, rootpart.Position.Y, targetRoot.Position.Z))