How do I fix this custom camera script?

I made a custom camera from a part that rotates around the character wherever the mouse moves, it works decently well. The problem is that 1. it moves WAY too fast, and 2. if you put your mouse on the far ends of the screen, the camera will spin extremely fast. I’m pretty sure number 2. is caused by pointing the mouse at the skybox, making it almost infinite because I am using mouse.Hit.p for this. I was thinking about only rotating the camera based on the mouse’s X axis, but I can’t find how to do that, I could only find mouse.Hit.p. If someone gives me a way to rotate this around only the X axis of the mouse, I will still mark it as a solution.

GIF: https://gyazo.com/732a810842ae63a3ca7a2f3f1aa263cb

SCRIPT:

RS.RenderStepped:connect(function()
	if c.Humanoid ~= nil and c.Humanoid.Health > 0 then 
		local CamPos = CFrame.new(c.HumanoidRootPart.Position, mouse.Hit.p) * CFrame.new(0,4,9).p
		BP.Position = CamPos
		workspace.CurrentCamera.CameraType = "Scriptable"
		workspace.CurrentCamera.CFrame = CFrame.new(CamBlock.Position, mouse.Hit.p)

updated script
This one only rotates up and down but I can’t find out how to make it side by side

	local position = Vector3.new(mouse.X, mouse.Y)
	if c.Humanoid ~= nil and c.Humanoid.Health > 0 then 
		local CamPos = CFrame.new(c.HumanoidRootPart.Position, position) * CFrame.new(0,4,9).p
		BP.Position = CamPos
		workspace.CurrentCamera.CameraType = "Scriptable"
		workspace.CurrentCamera.CFrame = CFrame.new(CamBlock.Position, position)

You can’t make it move side to side if the CameraType is Scriptable.

One solution:
Set the position of the camera first, and then lerp the camera to a rotated CFrame.

an example is like this >>

local CF = --Target CFrame
workspace.CurrentCamera.CFrame = CFrame.new(CF.Position,(other stuff such as look vector,right vector and up vector))
workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame:Lerp(CF,0.1)