Camera Glitch When Target is Close

I’m having some issues with the lock-on system I am currently using, and I have been searching for hours to find a solution to this.

I found this post but the solution did not work for me:

The lock-on works fine, but the camera spins everywhere when I get close to the target.

This is my code:

   local B = Target.HumanoidRootPart.Position
   local A = c.HumanoidRootPart.Position
   local Offset =, 2, 6.5)
   local V = B + ((A + Offset) - B).Unit * ((A - B).Magnitude + 10.25)

   local CamPos =, B).Position

   Camera.CameraType = "Scriptable"
   Camera.CFrame =, Target.HumanoidRootPart.Position)
   Camera.CFrame =, Target.HumanoidRootPart.Position)