Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I resort my table and still use it?

Asked by 7 years ago

I have the original coding here:

local player = game.Players.LocalPlayer
local slots = script.Parent.Background.Tool.Slots:GetChildren()
-- Sorting system --
local resorted = {}
for i, v in pairs(slots) do
    print(v)
    table.insert(resorted, tostring(v))
end
table.sort(resorted)
print(table.concat(resorted, ' '))

player.Inventory.ChildAdded:connect(function(obj)
    if obj.ItemType.Value == 2 then
        for i, slots in pairs(resorted) do
            if slots.Image == "" then
                local find = game.ReplicatedStorage.InvenFrames.Tools:FindFirstChild(obj.Name)
                slots.Image = find.Image
                slots.ItemName.Value = obj.Name
                    for i, clone in pairs(find:GetChildren()) do
                        if clone:IsA("Folder") then
                            clone.Parent = slots
                        return nil
                    end   
                end 
            end
        end
    end
end)

But when I go back to use the newly sorted version, I can't. Any help?

1
On line 7, do you mean v.Name? User#11440 120 — 7y
0
No xXLegendarySoldierXx 129 — 7y
0
What does your question mean? What do you mean "go back to use" it? What is the actual problem? What are you trying to do? What happens instead? BlueTaslem 18071 — 7y
0
So, whenever an item goes into the inventory a picture goes to a slot but, the slots do not fill correctly. So the spots get filled randomly and in sequential order. Whenever I resorted it, I couldn't go back and use the sorted table. xXLegendarySoldierXx 129 — 7y

Answer this question