Lets say the second values of the tables are ID’s but the thing i wanna sort are the 1, 4, 1. I tried this but it printed 1 = 2, 4 = 6.(btw i tried the script that i just wrote and it gave an error but my script is like a table with prices of gamepasses and the ID next to it, and i want to sort on the price.)
How do i do this?
That’s prob because you have a dictionary and not an array, and table.sort works with arrays.
Try this:
local gamePasses= {
{1,1111}; -- you can decide which here represents the gamepass ID's
{4,4444};
{2,222};
}
table.sort(gamePasses, function(a,b)
return a[2] > b[2] --you can change it to a[1] and b[1] if you want to sort the first value
end)
for i,v in pairs(gamePasses) do
print(v[1], v[2])
end