Why isn't this super simple script not working?

Ok so the solution might be super simple and I’m just blind

Here is the script:

local camera = game.workspace.Camera
local part = game.workspace.IntroCam

local Player = game.Players.LocalPlayer


camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = part.CFrame
wait(17)
camera.CameraSubject = Player.Character.Humanoid 
camera.CameraType = Enum.CameraType.Custom

Very simple right? Yet it doesnt work and there are no errors!

The script is enabled, it is in startergui, and is a local script. What am I missing here?

1 Like

did you mean to use CurrentCamera?

local camera = game.Workspace.CurrentCamera -- current camera
local part = game.Workspace.IntroCam

local Player = game.Players.LocalPlayer


camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = part.CFrame
wait(17)
camera.CameraSubject = Player.Character:WaitForChild("Humanoid")
camera.CameraType = Enum.CameraType.Custom

Didn’t work. :confused:


I found a capitalization issue in the script. I have just edited the code in my previous post. Try using that code again.

Didnt work…


local camera = game.workspace.CurrentCamera

 --please make sure that you have a part named "IntroCam" in workspace
local part = game:GetService("Workspace"):WaitForChild("IntroCam")

local Player = game.Players.LocalPlayer


camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = part.CFrame
task.wait(17)  --use task.wait insead of wait!
camera.CameraSubject = Player.Character.Humanoid 
camera.CameraType = Enum.CameraType.Custom

Didnt work and yes intro part is a child of workspace

1 Like

Try adding prints in the script and see which print messages show in the output and which ones doesn’t. This is to see where the script could have stopped running its code.

Side note, use workspace not game.Workspace. It does the same thing except takes up less space and is slightly faster. Other than that, I see two issues here.


Change this to local camera = workspace.CurrentCamera.


The default camera scripts can load after your script; when they do they set the camera to Enum.CameraType.Custom which would break your script.


Solution
local camera = workspace.CurrentCamera
local part = workspace:WaitForChild("IntroCam") -- Waits for IntroCam to load.  Ensures script doesn't break on slow internet or computers
local Player = game:GetService("Players").LocalPlayer -- Less likely to break than game.Players

local connection  = nil

local function setcamera()
    camera.CameraType = Enum.CameraType.Scriptable
    camera.CFrame = part.CFrame
end

setcamera()
connection = camera:GetPropertyChangedSignal("CameraType"):Connect(setcamera) -- Changes the camera type back to scriptable

task.wait(17) -- wait() is deprecated

connection:Disconnect() -- Disables connection so it cannot change the camera type anymore
connection, setcamera = nil, nil -- Deletes not-needed variables

camera.CameraSubject = Player.Character.Humanoid
camera.CameraType = Enum.CameraType.Custom
2 Likes

Didn’t work

Must be something wrong with my studio…

Edit: Yep I rebooted my studio and it is working now

2 Likes