For loop doesn't run through all children

None of these work, they all skip 1 item. Can someone help me?

for i,v in pairs(game.ReplicatedStorage.Items.Backpacks:GetChildren()) do
    print(v.Name)
end
for i,v in pairs(module.Backpacks) do
    print(i)
end
2 Likes

What item do they skip? Can you show us the hierarchy of the objects in the Explorer please?

It skips the one called “Advanced”
image
image

Are both loops supposed to have the same outcome, but one for index and one for value? Also perhaps a larger image on where the script is located please.

Those 2 for loops i had was just to test and see which one it skips. The script is in ServerScriptService, and the module is here:
image

Can you run the game and check through the explorer if the “Advanced” backpack is still there when you run it?

I already did that and its there

Are you running the loop on the client or on the server?

The script is on the server
image

Instead of module.Backpacks shouldn’t it be:

for i,v in pairs(script.Parent.Backpacks:GetChildren()) do
    print(i)
end

And that would be a script instead of a ModuleScript? If the module script is meant to store that table then why is module.Backpacks used? Or if I missed something, I’m a bit blur sorry.

Yeah
image

the module is to store the info for all the items, like the price, storage and id.
The folder is for the MeshPart.

Oh and that script i provided probably isn’t accurate or anything like that, its just to like show that it doesn’t go through all of the items.

The actual script is irrelevant rn because the only problem i have is one of the items getting skipped

Oh then in that case, can we see the children of the advanced model and the children of another model?

image

Then the only thing I can think of is that there is a problem with the Attachment? Maybe you could try spawning (if the full script involves spawning the item there) that item alone? Perhaps it’s just that model. So just do:

print(game.ReplicatedStorage:WaitForChild("Items").Backpacks.Advanced.Name)

And just see if that works.

Ima try that.
It also skips the item when u just do a for loop and print the names.

image

Hmm. Sorry if I’m taking really long to solve this. I have one last possible solution. Maybe do:

wait(3)
for i,v in pairs(game.ReplicatedStorage.Items.Backpacks:GetChildren()) do
    print(v.Name)
end

There would be better options using WaitForChild() but perhaps try this and see if Advanced maybe takes longer to load into the game?

Try this. Should work just fine.

local Backpacks = game:GetService('ReplicatedStorage').Items.Backpacks
local GetChildren = Backpacks:GetChildren()
for _, v in ipairs(GetChildren) do
    print(v.Name)
end