Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why doesn't this sort double-digit numbers?

Asked by 6 years ago
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

Log in to vote
0
Answered by
Sir_Melio 221 Moderation Voter
6 years ago
Edited 6 years ago

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).

0
thank you! ArcticDev 9 — 6y
Ad

Answer this question