How to stop Camera from glitching (on my cam system)

hi, i have a camera system where it tracks the head orientation , but i noticed that when you are looking down or up, the camera begins to change to right and left, I think it’s because the animations, because on my walk animation (not much movement), this doesn’t happens, but on my run one, it does, is there any way i could stop it from doing that?

task.wait(.1)
local TweenService = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local UserGameSettings = UserSettings():GetService("UserGameSettings")
local localPlayer = Players.LocalPlayer
local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
local camera = workspace.CurrentCamera
local head = character:WaitForChild("Head")
local hrp = character:WaitForChild("HumanoidRootPart")
local humanoid = character:WaitForChild("Humanoid")
humanoid.CameraOffset = Vector3.new(0,0.51,-0.65)
local lastOffset = Vector3.zero
local Intensity = 0.55 -- Original is 0.5 , Default is 0
local Turn = 0
local Lerp = function(a, b, t)
	return a + (b - a) * t
end;
RunService.RenderStepped:Connect(function(delta)
	--// Functions //--
	local MouseDelta = UserInputService:GetMouseDelta()
	Turn = Lerp(Turn, math.clamp(MouseDelta.X, -22, 22), (3 * delta))
	local _,_,Roll = head.CFrame:ToOrientation()	
	
	camera.CFrame *= CFrame.Angles(0,0,Roll * Intensity) * CFrame.Angles(0, 0, math.rad(Turn))
end)
1 Like