Custom Camera not working in Studio

My custom first person camera script works fine in Roblox but when I play it in Studio, the camera doesn’t rotate, how do I fix this?

My camera script in StarterPlayerScripts

local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")

local Camera = workspace.CurrentCamera
local Player = Players.LocalPlayer
local Character = workspace:WaitForChild(Player.Name)

local function SetCamera(cameraType, fieldOfView, cameraSubject)
	Camera.CameraType = cameraType
	Camera.FieldOfView = fieldOfView
	Camera.CameraSubject = cameraSubject
end

local DefaultRotation = Vector2.new(0, 0)
local DefaultPosition = Character:WaitForChild("Head").Position

local Rotation = DefaultRotation
local Position = DefaultPosition

local MouseSens = -0.25

local function UpdateCamera()
	SetCamera(Enum.CameraType.Scriptable, 80, Character:WaitForChild("Humanoid"))

	local rotationCFrame = CFrame.Angles(0, Rotation.X, 0) * CFrame.Angles(Rotation.Y, 0, 0)

	Camera.CFrame = rotationCFrame + Position
	Camera.Focus = Camera.CFrame - Vector3.new(0, Camera.CFrame.Position.Y, 0)

	local delta = UserInputService:GetMouseDelta()

	Position = Character:WaitForChild("Head").Position
	Rotation += delta * math.rad(MouseSens)

	if Rotation.Y < -1.5 then
		Rotation = Vector2.new(Rotation.X, -1.5)
	elseif Rotation.Y > 1.5 then
		Rotation = Vector2.new(Rotation.X, 1.5)
	end

	local rx, ry, rz = Camera.CFrame:ToOrientation()

	Character:PivotTo(CFrame.new(Character.PrimaryPart.CFrame.Position) * CFrame.fromOrientation(0, ry, 0))
end

RunService:BindToRenderStep("CustomCamera", Enum.RenderPriority.Camera.Value, UpdateCamera)
1 Like