Local script for the camera movements:
local function updateCameraPosition()
if equipped then
local delta = uis:GetMouseDelta()
local mX = mouse.X
local mY = mouse.Y
local screenWidth = workspace.CurrentCamera.ViewportSize.X
local screenHeight = workspace.CurrentCamera.ViewportSize.Y
local relativeMouseX = (mX - (screenWidth / 2)) / (screenWidth / 2)
local relativeMouseY = (mY - (screenHeight / 2)) / (screenHeight / 2)
local yawSpeedFactor = math.abs(relativeMouseX) * maxRotationSpeed + rotationSpeed
local pitchSpeedFactor = math.abs(relativeMouseY) * maxRotationSpeed + rotationSpeed
yaw = yaw - (relativeMouseX * yawSpeedFactor)
pitch = math.clamp(pitch + (-delta.Y) * pitchSpeedFactor, pitchMin, pitchMax)
local rotation = CFrame.Angles(math.rad(pitch), math.rad(yaw), 0)
local targetPosition = head.Position + offset
camera.CFrame = CFrame.new(targetPosition) * rotation
updateViewModel()
end
end