I'm trying to make a server leaderboard but don't know how to sort the players by how much money they have. I have the basic functionality scripted, all I need is just the sorting and moving of positions when a player passes another player.
local replicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Template = replicatedStorage:WaitForChild("Template")
Players.PlayerAdded:Connect(function(Plr)
local newTemplate = Template:Clone()
newTemplate.Name = Plr.Name
newTemplate.Position = UDim2.new(0, 0, newTemplate.Position.Y.Scale + (0.1 * #script.Parent.GUI.Holder:GetChildren()), 0)
newTemplate.Parent = script.Parent.GUI.Holder
newTemplate.Rank.Text = "#0"
newTemplate.Player.Text = Plr.Name
wait(2)
newTemplate.Cash.Text = Plr.leaderstats.Cash.Value
end)
Players.PlayerRemoving:Connect(function(Plr)
for i, v in pairs(script.Parent.GUI.Holder:GetChildren()) do
if v.Name == Plr.Name then
v:Destroy()
end
end
end)
