Custom Camera not working properly

  1. **What do you want to achieve?
    I want my camera to be smoother, cameras y rotation to rotate around humanoid root part instead of itself.
  2. **What is the issue?
local uis = game:GetService("UserInputService")
local camera = workspace.CurrentCamera
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local hrp = character:WaitForChild("HumanoidRootPart")

local offset = CFrame.new(Vector3.new(2, 5, 7))
local rotationOffset = CFrame.Angles(math.rad(-30), 0, 0)

local finalOffset = offset * rotationOffset
local sensitivity = 0.06
local rotSens = 0.01
local isMouseLocked = false

local cameraOffset = CFrame.new(Vector3.new(0, 0, 0))

camera.CameraType = "Scriptable"
camera.CFrame = hrp.CFrame * finalOffset * cameraOffset

function toggleMouseLock()
	isMouseLocked = not isMouseLocked
	uis.MouseBehavior = isMouseLocked and Enum.MouseBehavior.LockCenter or Enum.MouseBehavior.Default
end

uis.InputBegan:Connect(function(input, gameProcessedEvent)
	if not gameProcessedEvent and input.UserInputType == Enum.UserInputType.MouseButton2 then
		toggleMouseLock()
	end
end)

if humanoid.Health > 0 then
	game:GetService("RunService").Heartbeat:Connect(function()
		local targetCFrame = hrp.CFrame * finalOffset * cameraOffset

		if isMouseLocked then
			local mouseDelta = uis:GetMouseDelta()
			local X = -mouseDelta.X * sensitivity
			local Y = mouseDelta.Y * rotSens
			local rotation = Vector3.new(0, X, 0)
			local targetOffset = hrp.CFrame * CFrame.Angles(0, rotation.y, 0)
						
			hrp.CFrame = hrp.CFrame:Lerp(targetOffset, 0.1)

			local cameraRot = CFrame.Angles(Y, 0, 0)
			cameraOffset = cameraRot * cameraOffset
			local targetCamOffset = targetCFrame * cameraOffset
			
			camera.CFrame = camera.CFrame:Lerp(targetCamOffset, 0.1)
		else
			camera.CFrame = camera.CFrame:Lerp(targetCFrame, 0.1)
		end
	end)
end