Can't find children of PlayerGui

I need to find children of PlayerGui, but it keeps resulting in infinite yield or an error. Here is the script:

local player = game:GetService("Players").LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local testingScreen = playerGui:WaitForChild("TestingScreen")
local testingFrame = testingScreen:WaitForChild("TestingFrame")
local manageResults = testingFrame:WaitForChild("ManageResults")
local openManageResults = manageResults:WaitForChild("OpenManageResults")

The script is able to find player and playerGui without a problem, but It can’t find TestingScreen. Here is the explorer window for starterGui:
Screenshot 2022-06-04 110322
How do I fix this?

Is this a normal or local script?

I’d just do:

local player = game:GetService("Players").LocalPlayer
local playerGui = player.PlayerGui
local testingScreen = playerGui.TestingScreen
local testingFrame = testingScreen.TestingFrame
local manageResults = testingFrame.ManageResults
local openManageResults = manageResults.OpenManageResults

This will cause an error instead of infinite yield error. This will not fix the problem.
@Valkyrop if it’s a server script he wouldn’t be able to use .LocalPlayer, thus not being able to find the PlayerGui itself:

I think the issue is you reusing the WaitForChild in the children of the TestingScreen. I tried this and it seems to work fine for me.

Instances:
image

Code:

local PLAYERS = game:GetService("Players")
local LOCALPLAYER = PLAYERS["LocalPlayer"]
local PLAYERGUI = LOCALPLAYER:WaitForChild("PlayerGui")
local GUI = PLAYERGUI:WaitForChild("TestingScreen")
for INT, ITEM in pairs(PLAYERGUI:GetChildren()) do
	print(INT, ITEM)
end

Output:

  22:22:22.383  1 BubbleChat  -  Client - LocalScript:6
  22:22:22.383  2 Chat  -  Client - LocalScript:6
  22:22:22.383  3 Freecam  -  Client - LocalScript:6
  22:22:22.383  4 TestingScreen  -  Client - LocalScript:6

Tried to get all the descendants of the TestingScreen, and it works.
image

Snippet:

local GUI = PLAYERGUI:WaitForChild("TestingScreen")
for INT, ITEM in pairs(GUI:GetDescendants()) do
	print(INT, ITEM)
end

Output:

  22:30:30.578  1 TestingFrame  -  Client - LocalScript:6
  22:30:30.578  2 ManageResults  -  Client - LocalScript:6
  22:30:30.578  3 OpenManageResults  -  Client - LocalScript:6
1 Like

It is a local script in starter player scripts.