:GetDescendants() is returning empty table

Hello Everyone I’ve been making a UI controller which changes the theme of gradients using collection service.
In order to change it I have to change it in The StarterGui and also the PlayerGui.

The collection service tag isn’t there on the Gui in playerGui so I tried Getting the Descendants of the player gui and finding it by the table.

But the player:GetDescendants() is returning an empty table for some reason.

Heres the script

local UIGradientController = {}

local player: Player = game.Players.LocalPlayer
local Cs = game:GetService("CollectionService")

function UIGradientController:ChangeTheme(c1,c2)
    for _,v in ipairs(Cs:GetTagged("Gradient")) do
        local playerDescendants = player.PlayerGui:GetDescendants()
        --Change the existing one
        local UI = playerDescendants[v]
        print(playerDescendants) -- prints {}
        if (UI ~= nil) then 
            UI.UIGradient.Color = ColorSequence.new(c1,c2)
        end

        local Gradient = v:WaitForChild("UIGradient")
        Gradient.Color = ColorSequence.new(c1,c2)
    end
end

function UIGradientController:Start()

    UIGradientController:ChangeTheme(Color3.new(0,0,0), Color3.new(1,1,1))
end


return UIGradientController

I am using AeroGameFrameWork but it doesn’t matter in this case.

Any reason why its doing it. Also if any other method of doing this is also appreciated.

Also note that the Gui in StarterGui is working

If you need to get only one search deep i would recommend using :GetChildren() instead as it only return the children and not the all children after it

Also is there an arrow before the {} when printing it?

But I need to get all to find the UI.

No.

Well then i don’t know the problem with it then if it might be any help here is a page about the the :GetDescendants() in case there’s a reason for it :GetDescendants()

1 Like

I’m thinking that this script runs before anything exists in PlayerGui, try adding a wait(5) before the for loop and see if it works.

2 Likes

I am not on my pc rn I’ll try it asap.

You’re trying to print the whole table, which won’t work that way. You’ll have to use a for loop to go through the descendants, or you can do table.unpack()

I am using the new output which lets you print tables.

Oh right, completely forgot that’s a thing now
Not sure what the problem is then. You should probably try Rynappel’s fix instead.

2 Likes

Btw if you have any method of achieving this, It will be appreciated.