I added a lot of stuff to my game and I’ve noticed that my scripts are breaking because not all necessary descendants are loaded into the game when they are running.
These scripts are in StarterPlayerScripts.
I just ran a quick test, 2526 descendants are loaded when the scripts first run and search for their parts. 10 seconds later its 13851. This is literally going to destroy my game if I dont find a solution. I’ve tried game.isLoaded but it returns true even when not everything i sloaded
local function AddRegionsToChilds(Parent:Folder)
for _, Folder:Instance in Parent:GetChildren() do
if Folder:IsA("Folder") then
print(Folder:GetChildren()) --the chlidren literaly do not exsist when this loop is ran
for _, Part: Instance in Folder:GetChildren() do
if not Part:IsA("BasePart") then continue end
RegionHandler.CreateZone(Folder.Name, Part.Name, Part)
end
end
end
end
local function AddRegionsToChilds(Parent:Folder)
for _, Folder:Instance in Parent:GetChildren() do
if Folder:IsA("Folder") then
local function onChildAdded(Part)
if not Part:IsA("BasePart") then continue end
RegionHandler.CreateZone(Folder.Name, Part.Name, Part)
end
Folder.ChildAdded:Connect(onChildAdded)
for _, Part: Instance in Folder:GetChildren() do
onChildAdded(Part)
end
end
end
end