Attempt to index nil with 'CFrame' for camera part

For some reason, the simple camera script just tells me that CFrame isn’t apart of the camera part even though it’s there in-game

local cam = workspace.CurrentCamera
local camPart = workspace:FindFirstChild("MenuCam")
local mouse = game.Players.LocalPlayer:GetMouse()

repeat
	task.wait()
	cam.CameraType = Enum.CameraType.Scriptable
until
cam.CameraType == Enum.CameraType.Scriptable

cam.CFrame = camPart.CFrame

I’m not sure why it does that, this exact script worked before so i’m not sure how this can be fixed

1 Like

Could you try to use :WaitForChild instead?

:FindFirstChild only checks if it exists, :WaitForChild waits for it to exist.
This is due to the Client script running before the world has loaded.

1 Like

If it’s pointing to cam: workspace.CurrentCamera shall work, if it’s in LocalScript only!

If it’s pointing to camPart: workspace:FindFirstChild(“MenuCam”), listen to Kayoh

By default, workspace.CurrentCamera will redirect to workspace.Camera, resulting in the same issue if the Camera doesnt exist yet.

1 Like

Use

local camPart = workspace:WaitForChild("MenuCam")

as @vrs2210 suggested. The Part doesn’t exist the moment the player joins

1 Like
local Players = game:GetService("Players")

local cam = workspace.CurrentCamera
local camPart = workspace:WaitForChild("MenuCam")::Part
local mouse = Players.LocalPlayer:GetMouse()

cam:GetPropertyChangedSignal("CameraType"):Wait()
cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = camPart.CFrame

i tried that before and it says possible yields

let me see and if it works again hold on

Becouse your game has StreamingEnabled.
Object you are trying to get simply is not streamable.
Put it inside atomic model.

NVM ACTUALLY PERSISTENT

https://create.roblox.com/docs/workspace/streaming#persistent

I’ve switched it to waitForChild but it still shows infinite possible yields, but i’ll see if putting it in a persistent model works

Okay it just says the camera part isnt in the model lol

is there anything else i need to do?

local cam = workspace.CurrentCamera
local camModel = workspace:WaitForChild("CamModel")
local camPart = camModel.MenuCam
local mouse = game.Players.LocalPlayer:GetMouse()

repeat
	task.wait()
	cam.CameraType = Enum.CameraType.Scriptable
until
cam.CameraType == Enum.CameraType.Scriptable

cam.CFrame = camPart.CFrame

Can you clarify that you infact have streaming enabled?
If so is model streaming behavior Persistent?

1 Like

where can i check that btw? sorry for not clarifying earlier lol

edit: nvm i found it

okay it works tysm for the help dude

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.