New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

How to use table.sort, from highest to lowest?

Asked by 10 days ago

I already tried looking for information on developer roblox but I didn't find anything useful. What I'm trying to do is to sort a value based on the value inside of it.

For example:

I have a number value called: Apple. This value is used to find the quantity of the item. Then inside of the value there's another number value that determines the rarity of the item.

I'm trying to use this script:

for i,v in pairs(game.ReplicatedStorage.PlayerData:WaitForChild(game.Players.LocalPlayer.Name):GetChildren()) do
        if v.Type.Value == "Item" then
                if v.Value >= 1 then
                    local item = script.ItemTemplate:Clone()
                    item.Parent = script.Parent.Inventory.ItemInv
                    item.Visible = true
                    item.Position = UDim2.new(0,x,0,y)
                    item.Name = v.Name
                    if v.Value > 1 then
                        item.ItemName.Text = v.Name.." ("..v.Value.."x)"
                    else
                        item.ItemName.Text = v.Name
                    end
                    item.Rarity.Text = v.Rarity.Value
                end
        end
end

Where exactly can I use table.sort, and how?

Answer this question