I would like to sort the players from a leaderstats. Here's what I tried
function Sort(Frame, Points, team)
local t = {}
local order = {}
for i, v in pairs(Frame:GetChildren()) do
if v:FindFirstChild(Points.Name) and v:FindFirstChild("PlrName") then
table.insert(t, tonumber(v[Points.Name].Text))
table.insert(order, v)
end
end
table.sort(t, function(a,b) return tonumber(a) < tonumber(b) end)
local ypos
if team == false then
ypos = 0
else
ypos = 25
end
local TB = 1
for i, v in pairs(order) do
if v:FindFirstChild(Points.Name) then
if tonumber(v:FindFirstChild(Points.Name).Text) == t[TB] then
v.Position = UDim2.new(0,0,0,ypos)
TB = TB + 1
ypos = ypos + 25
end
end
end
end
Frame is the parent of the Frames that show the players. Points is the thing that gets sorted. Team is if there are teams. Can anyone help me?

1 comment
You should probably use a numerical loop