Help with camera

So I tried goofing around with this code but still couldnt figure out how to do this.

local connect = run.RenderStepped:Connect(function()
    local np = Vector2.new(mouse.X,mouse.Y)
    local center = Vector2.new(camera.ViewportSize.X/2, camera.ViewportSize.Y/2)
    local difference = np - center

    local outcome = Vector2.new(difference.Y/center.Y, (difference.X/center.X)*maxDegree)

    camera.CFrame = CFrame.Angles(-outcome.X, -outcome.Y,0) + workspace.Cameras:FindFirstChild(location).Position
end)

What this code is rotates a part in the directions of the players mouse. The parts orientation is (0,0,0) at default. If I was to change the direction the default orientation is when the script starts working it still faces (0,0,0) at default. How can I make it so it rotates around the base orientation instead of always just (0,0,0)

Can you draw what you’re trying to do?

Ok well here is a camera part


If you move the mouse up it points upwards

What I want to do is that if I make it so before I start testing if I rotate it like this

When you move the mouse upwards it rotates like this

But how it actually works rn it will only be like this

And when it rotates its like this

Have you tried doing this with CFrame.lookAt instead? This is the preferred way to do it, it takes a starting point and a target point to look at.

How can I do this and make it point towards the players mouse?

You can get the mouse position in 3D using mouse.Hit.Position and use that as the target to CFrame.lookAt

You’d get the position of the mouse and return a new coordinate frame with an origin point of wherever the camera part is, and have it face towards the position of the player’s mouse.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Camera = workspace.CurrentCamera
Camera.CameraType = Enum.CameraType.Scriptable

Camera.CFrame = CFrame.lookAt(OriginPosition, PositionToLookAt)

In this case the  lookat position would be mouse.Hit.Position

Yes this would work but then you can look everywhere, I only want you to be able to look in certain directions by X amount of degrees. Thats what the code rn does