Sorting a table by values, not index

As your data is in a dictionary, it is unordered, hence why table.sort() doesn’t do the required outcome. However, I will try and create something that will result in the desired order being achieved. Might take me a bit though…

edit:
Found this post here:

Their code is:

local array = {}
for key, value in pairs(dictionary) do
	array[#array+1] = {key = key, value = value}
end
table.sort(array, function(a, b)
	return a.value > b.value
end)
2 Likes