How can I limit the x-axis of the camera without intervening in the rotation?

Puedes escribir tu tema como quieras, pero tienes que responder a estas preguntas:

  1. ¿Qué quieres conseguir? Quiero poner un limite al eje x de mi cámara para que cuando llegue a ese limite rote gire la cámara y si nuestro jugador avanza gire el cuerpo en relación a donde la cámara apunte(No se si me explico muy bien)

  2. **Incluye capturas de pantalla o vídeos si es posible
    robloxapp-20240620-1524566.wmv (2.0 MB)

  3. ¿Qué soluciones has probado hasta ahora? Probé varias soluciones pero me dejaron más confuso que antes y después de explorar desde hace varios días en el foro y no encontrar nada decidí pedir ayuda (Cabe recalcar que soy nuevo en el foro, así que si tienen alguna recomendación en base a mejorar mi post sean bienvenidos)

ENGLISH

  1. **What do you want to achieve? I want to put a limit to the x-axis of my camera so that when it reaches that limit it rotates the camera and if our player moves forward it rotates the body in relation to where the camera is pointing (I don’t know if I explain myself very well).
  2. **Include screenshots or videos if possible.

my internet is not working correctly and it won’t let me upload it, although I already uploaded it previously

  1. **What solutions have you tried so far? I tried several solutions but they left me more confused than before and after exploring for several days in the forum and not finding anything I decided to ask for help (I must emphasize that I am new to the forum, so if you have any recommendations based on improving my post are welcome).
-- local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")

local UserGameSettings = UserSettings():GetService("UserGameSettings")	

local localPlayer = Players.LocalPlayer
local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
local camera = workspace.CurrentCamera

localPlayer.CameraMode = Enum.CameraMode.LockFirstPerson

local head = character:WaitForChild("Head")
local hrp = character:WaitForChild("HumanoidRootPart")
local humanoid = character:WaitForChild("Humanoid")

local lastOffset = Vector3.zero
local cameraRot = Vector3.zero
local sensitivityMultiplier = Vector2.zero
local cameraClamp = {
	Y = NumberRange.new(-math.rad(80), math.rad(80)),
	X = NumberRange.new(-math.rad(70), math.rad(70))
}

local visibleParts = {
	"Torso",
	"Left Arm",
	"Right Arm",
	"Left Leg",
	"Right Leg",
}

local cameraFov = camera.FieldOfView

-- Función para actualizar la rotación de la cámara
local function UpdateCameraRotation()
	local mouseDelta = UserInputService:GetMouseDelta()
	local mouseSensitivity = UserGameSettings.MouseSensitivity

	cameraRot = Vector2.new(
		math.clamp(
		cameraRot.X - mouseDelta.X * mouseSensitivity * sensitivityMultiplier.X,
		cameraClamp.X.Min,
		cameraClamp.X.Max
		),
		math.clamp(
			cameraRot.Y - mouseDelta.Y * mouseSensitivity * sensitivityMultiplier.Y,
			cameraClamp.Y.Min,
			cameraClamp.Y.Max
		)
	)
end

-- Función para cambiar el FOV de la cámara
local function SetCameraFOV(newFOV)
	camera.FieldOfView = newFOV
end

-- Función para cambiar el offset de la cámara
local function SetCameraOffset(newOffset)
	humanoid.CameraOffset = newOffset
end

-- Función para cambiar la sensibilidad del ratón
local function SetMouseSensitivity(newSensitivityX, newSensitivityY)
	sensitivityMultiplier = Vector2.new(newSensitivityX, newSensitivityY)
end


-- Vinculamos una función para actualizar la cámara
RunService:BindToRenderStep("CameraUpdate", Enum.RenderPriority.Camera.Value, function(dt)
	if not head or not hrp or not humanoid then return end

	SetCameraFOV(89)  -- Cambia el FOV de la cámara a 89
	SetMouseSensitivity(0.002, 0.002)
	SetCameraOffset(Vector3.new(0,0.15,0.7))
	UpdateCameraRotation()

	local headCF = head.CFrame
	local hrpCF = hrp.CFrame

	local offset = lastOffset:Lerp(humanoid.CameraOffset, dt * 10)
	lastOffset = offset

	offset = offset.X * hrpCF.RightVector + offset.Y * hrpCF.UpVector + offset.Z * hrpCF.LookVector

	local hrpY, hrpX, hrpZ = hrpCF:ToOrientation()
	local raw = (headCF + offset) * CFrame.Angles(-hrpY, -hrpX, -hrpZ)

	local rot = CFrame.Angles(0, cameraRot.X, 0) * CFrame.Angles(cameraRot.Y, 0, 0)
	camera.CFrame = raw * rot
end)
	
-- Vinculamos una función para actualizar la rotación del personaje
RunService:BindToRenderStep("CharacterRotationUpdate", Enum.RenderPriority.Character.Value, function(dt)
	if not hrp then return end
	if humanoid.AutoRotate then return end

	local hrpCF = hrp.CFrame
	hrp.CFrame = CFrame.new(hrpCF.Position) * CFrame.fromOrientation(0, cameraRot.X, 0)

	
end)



-- Hacemos que el cursor del ratón esté siempre centrado y ajustamos la transparencia de las partes visibles del personaje
RunService.PreRender:Connect(function(dt)
	UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter

	for _, part in ipairs(character:GetDescendants()) do
		pcall(function()
			part.LocalTransparencyModifier = table.find(visibleParts, part.Name) and 0 or 1
		end)
	end
end)