I'm making a custom backpack, and it was going surprisingly smoothly up until the point that I needed to add items into certain slots. When an item is added into the player's backpack, my script runs through my custom backpack slots and checks if the ImageLabel is clear or not (if it's not clear, an item already occupies it). I've named my item slots ItemBox1, ItemBox2, and so forth. How can I make the script sort through the item boxes linearly, checking first ItemBox1, then ItemBox2, etc.? I imagine that I'd have to use table.sort, and if that's the case, can I have an example of how the function would be used?
backpack.ChildAdded:connect(function(child)
if child.ClassName == "Tool" then
table.insert(items, child)
print("item added")
for _, v in pairs(backpack:GetChildren()) do
table.insert(items, v)
for _, w in pairs(items) do
image = w.TextureId
tip = w.ToolTip
for _, box in pairs(backpackitems:GetChildren()) do
if box.ImageLabel.Image == "" then
print("found a box")
box.ImageLabel.Image = w.TextureId
return
end
end
end
print("bag loaded")
end
end
end)

2 comments
https://scriptinghelpers.org/questions/28269/how-does-tablesort-work#31721
Note: He asked me to close the question because the comment was sufficient.