Error occurred when I tried to use table.sort to sort scores

I was trying to use table.sort to sort int scores but It gave me this error: MainScript:84: attempt to index number with number. I have tried looking at other posts that explained table.sort but I could not find a clear enough explanation.

Lines 83 to 85 are below which is where the error occurred.

   table.sort(buildscores, function(i, j)
		return i[1] >= j[1]
	end)

The 2D array I am using for the scores is formated like this:

local buildscores = {
{intscore, player}
{intscore, player}}

This might help as its a little similar to your topic:

Doing this works for me

local buildscores = {
	{5, "you"},
	{7, "me"},
	{1, "someone else"}
}

table.sort(buildscores, function(i, j)
	return i[1] >= j[1]
end)

print(buildscores)

image


Could you show more of your code?

It could be that buildscores is actually just an array of numbers. (or what AustnBlox linked to)

2 Likes