Part is not a valid member of Workspace "Workspace"

I have this camera manipulation part but whenever
I get this error the whole script just breaks

However, I tried it out on my test place and it seems to be working fine

image

Here’s the part of the code

local Camera = workspace.CurrentCamera

repeat wait()
	Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable
Camera.CFrame = workspace.CameraPart.CFrame
7 Likes

Either there is nothing named CameraPart in workspace or it just has not loaded yet. You can use :WaitForChild() for that.

Example: workspace:WaitForChild(“CameraPart”)

22 Likes

well, would you look at that!
it’s working now. Thanks!

4 Likes

I am interested. We need to use WaitForChild every time for in our script to make a chance for lua script-(Roblox Studio script) load something fast? How this process working, any idea?

It’s a local script, the player may have loaded into the game, but the map didnt load on the client,. because of the device’s performance/ roblox limitations etc, therefore “not existing” yet. thats why they used waitforchild so the script knows that if it didnt find the part, instead yield the script until it does, to prevent errors

2 Likes

Thank you, now I understand, why in my first try on yesterday, my script worked and right now, it’s stopped working because map actually didn’t loaded fully as you said. Now I put WaitForChild and it’s start working again! I was always questioning myself why WaitForChild needed for, lol.

1 Like