Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why doesn't this sort double-digit numbers?

function LoadTable()
	scores = {}
	for i,v in pairs(script.Parent.LeaderBoard.Holder.players:GetChildren()) do
		table.insert(scores, i,v.Kills.text)
	end
		if scores[2] ~= nil then
		table.sort(scores, function(a,b) return a > b end)
	end
end

It sorts the numbers from least to greatest correctly, but once it is given the number 10 it sorts it as the number 1, not accounting for the 0 after it. Why is this happening?

Any help would be appreciated!

1 answer

✓ Accepted answer

It’s trying to sort it alphabetically because it’s a string. Try this line to make the inputted value a number instead: scores[#scores + 1] = tonumber(v.Kills.Text).

1 comment

0

thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.