My script can't find a part and I'm not sure why

I’ve got this line of code in a local script inside a GUI in StarterGui.

local campart = workspace.CARSPAWNINGPREVIEW.camerapart

However, for some reason it can not find the camerapart and keeps returning with

  22:13:53.918  camerapart is not a valid member of Folder "Workspace.CARSPAWNINGPREVIEW"  -  Client - sc:4
  22:13:53.918  Stack Begin  -  Studio
  22:13:53.919  Script 'Players.socixlizr.PlayerGui.CarSpawning.sc', Line 4  -  Studio - sc:4

I’ve tried a waitforchild, and ensured it is also where I am calling it to be.

image

3 Likes

You should use Instance | Roblox Creator Documentation to wait for the instance to exist in case the instance does not exist yet when called.

local campart = workspace:WaitForChild("CARSPAWNINGPREVIEW"):WaitForChild("camerapart")
2 Likes

Already tried that, it finds the folder but then can’t find the part.

Did you use WaitForChild in the part as well?

I done exactly what you done then it infinite yielded at finding camerapart.

Can you shove this in your script and tell us what it prints?

for _,v in pairs(Workspace.CARSPAWNINGPREVIEW:GetChildren()) do
    print(v)
end
4 Likes

Are you sure the part exists while the simulation runs? also are you sure it’s exactly named “camerapart” without any hidden characters like a space?

use FindFirstChild to return if the script found the object or not

local campart = workspace.CARSPAWNINGPREVIEW:FindFirstChild(“camerapart”)

if campart then
–code
end

For some reason it doesn’t find the parts but only finds the folders and models.

Make sure you haven’t named a Folder or something the same as the part.

You can see the explorer there.

My bad. Have you tried FindFirstChild()?

I tried a WFC and it didn’t do anything.

Its quite obvious then that to the script, those parts dont exist. Are these parts being interfered with any other scripts running on the client?

1 Like

Nope, the parts are only called for in that script, and the parts are there in game as you can clearly see.

Is the camerapart’s archivable property set to true?

1 Like

Affirm. Yes it is, and it is anchored and collidable.

local camerapart = workspace.CARSPAWNINGPREVIEW.camerapart or workspace:WaitForChild("CARSPAWNINGPREVIEW"):FindFirstChild("camerapart")

Try this. I’m just thinking of possible ways and it probably won’t work but it’s worth a try.

Tried both ways, neither of them work.

Interesting, after looking more closely I noticed that it prints the names of ‘Model’ and ‘PREVIEW’ which are then hyphenated with Client trailing after despite have a green line next to them, indicating it is being outputted by the server.

image