Camera rotating bug

Everything shown on a video
I dont think the problem is in code but if needed i can show.

Is your camera part anchored? Maybe ur camera is just spinning.

Yes my camera part is anchored

Are there any scripts moving it then?

Here is functions that moving camera part

local function RotateCameraSetup()
	UserInputService.InputBegan:Connect(function(input, gameProcessed)
		if gameProcessed then return end
		if input.UserInputType == Enum.UserInputType.MouseButton3 then
			isRotating = true
			UserInputService.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
			UserInputService.MouseIconEnabled = false
		end
	end)

	UserInputService.InputEnded:Connect(function(input, gameProcessed)
		if gameProcessed then return end
		if input.UserInputType == Enum.UserInputType.MouseButton3 then
			isRotating = false
			UserInputService.MouseBehavior = Enum.MouseBehavior.Default
			UserInputService.MouseIconEnabled = true
		end
	end)
end

local function RotateCamera()
	if not isRotating then return end


	local mouseDelta = UserInputService:GetMouseDelta()

	local dx = mouseDelta.X * Settings.MouseSensitivity
	print(dx)
	MainModule.RotateCamera(dx)
end


function _MainSetup()
	print("Setting up a camera")
	MainModule:SetUpCameraPart(player)
	RotateCameraSetup()

	
	task.wait(.1)
	mouse.WheelForward:Connect(MainModule._ZoomIn)
	mouse.WheelBackward:Connect(MainModule._ZoomOut)
	
	local lastMousePosition = UserInputService:GetMouseLocation() or Vector2.new(0, 0)

	mouse.Move:Connect(RotateCamera)

	RunService:BindToRenderStep("CameraFollow",Enum.RenderPriority.Camera.Value + 2, MainModule._RefreshCamera)
end

And a module script

function module.SetUpCameraPart()
	-- Assigning self
	self.Character = self.Player.Character
	
	if not self.Character then return end

	-- Creating a CameraPart (Camera Subject)
	local Part = Instance.new("Part",self.Character)
	Part.Name = "CameraPart"
	Part.CanCollide = false
	Part.CanTouch = false
	Part.Transparency = 1
	Part.Anchored = true
	Part.Orientation = Settings.CameraPartOrientation
	self.CameraPart = Part
	-- Camera Setup
	Part.Position = self.CurrentCameraPartPosition
	self.Camera.FieldOfView = Settings.MaxCameraFOV
	self.Camera.CameraSubject = self.CameraPart
end

function module._RefreshCamera(dt) -- Delta Time
	-- Making camera always above the player
	if not self.Character or not self.CameraPart then return end
	
	local HumanoidRootPart = self.Character:WaitForChild("HumanoidRootPart")
	if not HumanoidRootPart then return end
	
	local backwardVector = -HumanoidRootPart.CFrame.LookVector
	
	local targetPosition = (HumanoidRootPart.Position + Vector3.new(0,self.CurrentCameraPartPosition.Y,0))  + backwardVector * self.CurrentCameraPartPosition.Z
	
	
	local ClampedOrientation = {
		X = math.clamp(self.CurrentCameraPartOrientation.X,Settings.CameraPartOrientation.X,Settings.MinCameraPartOrientation.X),
		Y = self.CurrentCameraPartOrientation.Y, -- No 
		Z = math.clamp(self.CurrentCameraPartOrientation.Z,Settings.CameraPartOrientation.Z,Settings.MinCameraPartOrientation.Z),
	}


	self.CameraPart.Orientation = self.CameraPart.Orientation:Lerp(Vector3.new(ClampedOrientation.X,ClampedOrientation.Y,ClampedOrientation.Z),(1 * dt) * 3)
	self.CameraPart.Position = self.CameraPart.Position:Lerp(targetPosition,(1 * dt) * 3)
	self.Camera.CFrame = self.CameraPart.CFrame
	self.Camera.CameraType = Enum.CameraType.Scriptable
end


function module.RotateCamera(dx)
	if not self.Character or not self.CameraPart or not self.Camera then return end
	
	self.CurrentCameraPartOrientation += Vector3.new(0,dx,0)
end