The problem is that in the 2nd cycle only 2 layers are obtained, instead of 20 that are in the folder. I checked the whole script, the problem is in the 2nd cycle.
P.S. Layers are BasePart with attachments, all on the server side.
function layer.LayersInit(folderLayers:Folder,indexLayer:number)
local layers=folderLayers:GetChildren()
local layersTable={}
for index,_layer in ipairs(layers) do
_layer.Name="Layer"..tostring(index)
local allAttachmentsObject=_layer:GetDescendants()
if not layersTable[index] then
layersTable[index]={}
end
layersTable[index][indexLayer]={
layer=_layer,
name=_layer.Name,
attachments=(#allAttachmentsObject>0 and allAttachmentsObject) or nil
}
end
--This loop outputs the correct number of layers.
--for index, layerDataIndex in pairs(layersTable) do
-- print("Layer index:", index)
-- for _indexLayer, layerData in pairs(layerDataIndex) do
-- print(" - Layer name:", layerData.name, "Has attachments:", layerData.attachments ~= nil)
-- end
--end
for index,layerDataIndex in pairs(layersTable) do
for indexLayer,layerData in pairs(layerDataIndex) do
if layerData.attachments then
print("Layer has attachments:",layerData.name)
layer.LayerPreload(layerData.layer,layerDataIndex)
else
print("Layer has no attachments:",layerData.name)
layer.LayerPreload(layerData.layer)
end
end
end
end