Problem getting a folder's children from a local script in starter gui

so im trying to make security cameras one camera is working but now i am trying to make it so you can browse through different cameras(they are 3 in a folder inn the workspace)

i tried using local cameras = game:GetService("Workspace").cams:GetChildren() but the list is empty

i tried looking in the dev hub but i cant find exactly what i want, i found some things with the same issue but the solution was not working

the script is in starter gui (game.StarterGui.LocalScript) and the folder is in the workspace (game.Workspace.cams)

local rem  = game:GetService("ReplicatedStorage").remote
local cam = game.Workspace.CurrentCamera
local curr_cam = 1
local cameras = game:GetService("Workspace").cams:GetChildren()
print(cameras)--debug(output:{})
print(game.Workspace.cams:GetChildren())--debug(output:{})

rem.OnClientEvent:Connect(function()
	print(#cameras)--debug(output:0)
	cam.CameraType = Enum.CameraType.Scriptable
	cam.CFrame = workspace.cams["cam 1"].CFrame
	workspace.keyboard.ProximityPrompt.Enabled = false
	workspace["Modern Office Chair"].Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
		if workspace["Modern Office Chair"].Seat.Occupant ~= game:GetService("Players").LocalPlayer.Character.Humanoid then
			cam.CameraType = Enum.CameraType.Custom
			workspace.keyboard.ProximityPrompt.Enabled = false
		end
	end)
end)

thank you

1 Like

Could you check the cams folder at runtime to see if the parts are there?

1 Like

yes they are ill send pic at runtime:


i tried getting the children of the folder from the command bar in runtime it worked

1 Like

Did you yield the script? Local Scripts will run immediately. Even before the folders have loaded into the client. This can be fixed by doing:

workspace:WaitForChild("cams") --waits until the folder is loaded
workspace.cams:GetChildren()-- it should return now
2 Likes

thank you i tried doing so but it didnt work but you gave me the idea of defining the list after proximityprompt is trigerred that way the folder will load no matter what

2 Likes

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