In a Localscript, :GetDescendants sometimes only gets children

I have encountered an issue where sometimes, about 50/50, my localscript that is sorting through the descendants of a folder in workspace, will only return direct children. The localscript is pasted below, as well as a video showcasing the issue. Why is this happening? I feel like by the time both the Game and the Character are loaded, all descendants of workspace should also definitely be loaded. Even if I add a task.wait(), it STILL fails!

In the video attached, it is shown to work correctly on the first play, but then bug out on the second, with no code changes. Is this an engine bug? Should I report it?

local Players = game:GetService("Players")

if not game:IsLoaded() then
	game.Loaded:Wait()
end

local char = Players.LocalPlayer.Character or Players.LocalPlayer.CharacterAdded:Wait()

local spitefulTable = {}

local map = workspace.Map

for i, obj in pairs(map.Barrels:GetDescendants()) do
	table.insert(spitefulTable, obj)
end
print(spitefulTable)

Most likely issue with streaming. One of my games I had a problem where even if my character was right next to a part and was in the explorer, my code apparently couldn’t see it at all. Your issue is probably something similar so you’ll have to look at options for ensuring stuff is loaded properly.

I don’t use streaming enabled, so client should have every part loaded in. If I’m waiting for Game:IsLoaded, there’s no reason this should ever happen in the first place.

Still, there is clearly a problem with loading your descendants in, and it looks clear that game:IsLoaded does not prevent this. I think game:IsLoaded waits for the main components of your game to load, and makes sure the main parent instances are there. This is evident since this method is actually only really intended for local scripts in ReplicatedFirst, other localscripts will wait for the game to load before execution. I assume even if you have streamingenabled off, there is still some level of initial streaming in parts into the parent model. You can get around this, though, by connecting descendant added events to your models and catching them after you do the initial :GetDescendants.

You mean connecting and waiting for descendant added before the :GetDescendants?
I found that using :WaitForChild for a specific descendant of one of the barrels, before using :GetDescendants, avoids this issue pretty consistently. I would imagine you could also listen for descendant added, if you didn’t know what exactly would be a child.

Even still, localscripts not waiting for everything in workspace to fully load, feels like a bug to me.

Slowing down waiting for everything to fully load.

local Players = game:GetService("Players")

game.Loaded:Wait()
local char = Players.LocalPlayer.Character or Players.LocalPlayer.CharacterAdded:Wait()
local barrelsFolder = workspace:WaitForChild("Map"):WaitForChild("Barrels")

local spitefulTable = {}
for _, obj in pairs(barrelsFolder:GetChildren()) do
    if obj:IsA("Folder") or obj:IsA("Model") then
        table.insert(spitefulTable, obj:GetDescendants())
    end
end

print(spitefulTable)