# Table.sort issue

This is the thing.

``````local t =
{
1 == 2
4 == 6
1 == 9
}
``````

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
``````

the result should print:
1 1111
2 2222
4 4444

I hope I understood you

Huh i set the return to [2] and it sorted the first value.

Idk why but no matter what value in the return, it still sorts the first thing

Ok so now when i reversed the table it sorted it. BUT it printed this

While if i print the normal Gamepasses table there are more things with the price 5.

AAAAAH this isnt fun anymore i keep trying to sort the price BUT IT SORTS THE ID FOR NO REASON PLS HELP

FOR SOME REASON IDK WHAT I DID BUT IT WORKED. thx tho