CameraType won't set to Scriptable

So I created this really simple code to pick a random camera part and set the camera’s CFrame to it

game.Players.LocalPlayer.CharacterAdded:Wait()
local camera = game.Workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
game.Workspace.CurrentCamera.CFrame = game.Workspace.CameraObjects:WaitForChild("CameraPart"..math.random(1,3)).CFrame

Whenever I run this it doesn’t work and I get this error

ActivateCameraController did not select a module

How do I fix this? I have another script that does something similar but later on in the game. Why isn’t this one working?

I figured it out kind of, I put it inside a render stepped loop and for some reason it worked. If anyone knows why this works but what I tried before doesn’t work then please comment as I’m curious

game.Players.LocalPlayer.CharacterAdded:Wait()
local camera = game.Workspace.CurrentCamera
local RandomNum = math.random(1, 3)
camera.CameraType = Enum.CameraType.Scriptable
game:GetService("RunService").RenderStepped:Connect(function()
camera.CFrame = game.Workspace.CameraObjects:WaitForChild("CameraPart"..RandomNum).CFrame
end)

It seems to be an issue upon loading. I ran your script and got the same error.
I put a wait(1) at the top of the script and it works without errors

Try this

game.Players.LocalPlayer.CharacterAdded:Wait()
local camera = game.Workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
Camera.CameraSubject = Subject
game.Workspace.CurrentCamera.CFrame = game.Workspace.CameraObjects:WaitForChild("CameraPart"..math.random(1,3)).CFrame

Have you tried just setting it to Camera instead of CurrentCamera?

Try just yielding the thread until it sets it to the camera type you want.

local function setCameraTypeAsync(cameraType)
    repeat 
        CurrentCamera.CameraType = cameraType 
        wait() 
    until CurrentCamera.CameraType == cameraType 
end

Nothings wrong with the code itself. Just make sure it’s a local script in a GUI in the PlayerGui. Sorry if I’m late.