Need to rotate a cframe XY orientation and not the Z

Hello everyone, sorry for my bad english.
i’ve been trying to make a scriptable camera, make camera rotate and the body rotate , but the camera z orientation doesn’t stays in 0.
this is the code:

local camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local part = character.Part
local cameraSensitivity = 1
humanoid.AutoRotate = false

uis.InputChanged:Connect(function(input)
	if (input.UserInputType == Enum.UserInputType.MouseMovement) then
		local delta = input.Delta
		rootPart.CFrame = rootPart.CFrame * CFrame.Angles(0, -math.rad(delta.X) * cameraSensitivity, 0)
		part.CFrame = part.CFrame * CFrame.Angles(-math.rad(delta.Y) * cameraSensitivity,0,0)
	end 
end) 


runservice:BindToRenderStep("camera", 201, function()
	uis.MouseBehavior = Enum.MouseBehavior.LockCenter
	camera .CameraType = Enum.CameraType.Scriptable
	camera .CFrame = CFrame.new(rootPart.Position + Vector3.new(0, 2, 0)) * CFrame.Angles(math.rad(part.Orientation.X), math.rad(rootPart.Orientation.Y), 0)
	part.Orientation = Vector3.new(part.Orientation.X,0, 0)
end)

I’ve already tried this and other things but none worked

	camera.CFrame = CFrame.new(camera.CFrame.Position, Vector3.new(camera.CFrame.Rotation.X, camera.CFrame.Rotation.Y, 0))

That script just makes the camera not move.
How can i make so the camera z orientation stays in 0 but the x y orientation stills moves.
I’m not a professional scripter so if there is a way of making the code better tell me!

Can you draw what you are planning to have the camera do, or show an example of the type of movement from a video?

I need the camera to rotate in the X,Y axes (red and green lines) but always stay in 0 in the Z axis (blue line), because when the camera rotates in the Z axis it looks like this:

CFrame.lookAt does this:

It takes three Vector3s, the position of the camera, the position you want it to point at, and an “up” direction. In your case you want the Up direction to be Z. This will create a cframe as if you were pointing with a yaw-pitch “turret”, with the Up direction defining the yaw axis, and yaw being applied before pitch.

If you want it to be 0 on the Z axis, just multiply the lookvector by Vector3.new(1,1,0)

That might not be the problem, though, as @azqjanna said, your upvector might just be pointing the wrong way.