Sort function error that happens inconsistently

I am getting this error with table.sort() for sorting values lowest to highest.

The problem is is that it only happens sometimes so I cannot tell what is happening.

Log when it worked . (log shows the values):
Screenshot 2024-01-18 162023

Logs when it failed:


Sorting function (the value is in [1] of the score):

table.sort(scores, function(i, j)
			if i[1] and j[1] then
				if i[1] == j[1] then
					return true
				else
					return i[1] >= j[1]
				end
					
				
				
			elseif i[1] == nil and j[1] == nil then
				return false  
			elseif i[1] == nil then
				return false  
			elseif j[1] == nil then
				return true   
			else
				return false
			end
		end)

Help would be gratefully appreciated :slightly_smiling_face: .

Btw the "cleared " log in the second image is nothing to do with it.

Does anyone know how to fix this?