List of children in PlayerGui is empty

Hello Everyone.

Im have multiple different shop GUIs, and what im tyring to do here is opening the correct one (which is the one linked to the closest interactive block to the player).
Here is the problematic bit of my local script, a function which connected to the guiFinishEvent of the remote event

The Problem: the guiList is empty and that causes the for loop not to run, but im not sure why it is since there’s clearly gui Objects under PlayerGui :slightly_frowning_face:

                local player = game.Players.LocalPlayer 
                local guiList = player.PlayerGui:GetChildren()

                local function guiFinish(shopID)
                    print("function works")  --the function actually gets fired
                    
                    for v,b in pairs(guiList) do
                        print("looping")
                        local gui = b
                        local guiID = b:FindFirstChild("guiID")
                        
                        if (shopID.Value == guiID.Value) then
                            gui.Enabled = true
                        end
                    end                                        
                end
                guiFinishEvent.OnClientEvent:Connect(guiFinish)
1 Like

You need to show more code, I don’t see where you’ve declared s or player. Please update your post with this information.

The table will just be empty, not nil.

1 Like

Oh hey, thanks for Replying. I’ve just updated my post with the information you needed : D

The “s” was a small accident (left over from a previous bit of code i deleted).

Just before the for loop print(#guiList) to read the length of the table. It could be another issue, and tell me what you get.

Hmmmm interesting, output (length) was: 0

Ill try changing the directory using StarterGui instead of PlayerGui

You’ve declared guiList only once here, maybe try declaring this variable inside the function body? So that you get an updated list of the children each time the function is called?

1 Like

Oh yea, ill try that immediately.

Thanks! Teh for loop ran and I’m onto my next task! (Just another small less confusing error which i’m sure I’ll fix up xd, "(attempt to index local ‘shopID’ “a nil value”). I was using StringValues to store a special ID for each of my GUIs and interactive Parts in workspace, i’ll go look up the roblox api wiki now, cya and thx! :grinning:

U know what, that’s a good point. Why does work? Is it becuase maybe the contents of PlayerGui arent loaded fast enough before the local script runs?

1 Like