Thanks, it works now, but could i also maybe get an explanation for why it didn’t work earlier and why this works?
This is because when you use GetChildren it returns an array which has to be iterated by the array iterator ipairs. I would suggest to get used to using ipairs when using GetChildren.
Thanks for the explanation.
Could i also get some more help about this topic?
As a mentioned earlier in the topic, the item called Advanced
is getting skipped. It is no longer getting skipped in the script but for some reason it still doesn’t work with that exact item.
The script:
local module = require(game.ReplicatedStorage.Items.Config)
local Backpacks = game:GetService('ReplicatedStorage').Items.Backpacks
local GetChildren = Backpacks:GetChildren()
for i,v in ipairs(GetChildren) do
print(v.Name)
local item = v:Clone()
local stand = script.BackpackStand:Clone()
print(v.Name)
stand.Name = module.Backpacks[v.Name][1]
stand:SetPrimaryPartCFrame(CFrame.new(Vector3.new(0, -50, -10 + (module.Backpacks[v.Name][1] * 5.5))))
print(v.Name)
item.Name = "Backpack"
item.Anchored = true
item.CFrame = CFrame.new(Vector3.new(stand.PrimaryPart.Position.X, stand.PrimaryPart.Position.Y + 1.5, stand.PrimaryPart.Position.Z),stand.PrimaryPart.Position)
item.Orientation = Vector3.new(0,90,0)
print(v.Name)
item.Parent = stand
stand.Parent = workspace.Backpacks
print(v.Name)
end
It prints all of them but for some reason the item called Advanced
doesn’t work even though the scripts prints the name.
Bear with me since I’m on mobile, have you check the folder to see if it’s inside of it and it’s just not positioned correctly?
It’s not in workspace.Backpacks
I think he’s asking if the Advanced
item is in the correct spot, and not meshed in with one of the other items, making it LOOK like it didn’t clone to workspace.
Just a note, there’s nothing ipairs can be used to iterate over that pairs can’t (but in the case of hashmaps ipairs just won’t work when there’s no fully numerically indexed table and pairs will because it uses next
) , the only thing is ipairs is recommended to be used here because of its behavior (iterates on an i++ indice basis etc.) when working with arrays.
Just for testing try setting it’s position the the one before to try and see if it’ll actually parent itself.
Other than maybe some math being wrong, I can’t see anything wrong that would do this.
To the position for the item before it? That would just be doing module.Backpacks[v.Name][1] - 1
instead of module.Backpacks[v.Name][1]
Im pretty sure there is nothing wrong with the math, the problem is that the script apparently doesn’t parent the model, but it still prints after stand.Parent = workspace.Backpacks
.
Instead of having to change your index in the for loop, I would try setting the Advanced values to the one before it. This is to see if it has something to do with the position, which I know sounds redundant but anything is possible.
Maybe even try to print the position of the stand after the script “parents” it to the folder. It’s just strange it’s ignoring that specific item.
I made it print the Name, Position and the Parent’s name.
I just realized there is 2 items called Advanced in the module