So I have a custom leaderboard gui. All of the players frames are within a frame with a UIListLayout gui element. How would I be able to order the players to be from highest amount of kills to the lowest amount of kills, like shown below.
Local Script
--= Roblox Services =--
local Players = game:GetService("Players")
local StarterGui = game:GetService("StarterGui")
local TweenService = game:GetService("TweenService")
--= Object Refrences =--
local HideButton = script.Parent.HideButton
--= Internal Functions =--
local function addPlayerToLeaderboard(plr)
local templateFrame = script.Template:Clone()
templateFrame.Username.Text = plr.Name
templateFrame.Level.Text = plr:WaitForChild("leaderstats").Level.Value
templateFrame.Kills.Text = plr:WaitForChild("leaderstats").Kills.Value
templateFrame.Deaths.Text = plr:WaitForChild("leaderstats").Deaths.Value
templateFrame.Parent = script.Parent.PlayerContainer
templateFrame.Visible = true
-- templateFrame.Name = plr.Name
for _,leaderstat in pairs(plr:WaitForChild("leaderstats"):GetChildren()) do
leaderstat:GetPropertyChangedSignal("Value"):Connect(function()
templateFrame.Level.Text = plr:WaitForChild("leaderstats").Level.Value
templateFrame.Kills.Text = plr:WaitForChild("leaderstats").Kills.Value
templateFrame.Deaths.Text = plr:WaitForChild("leaderstats").Deaths.Value
end)
end
end
local function handleVisibility()
if HideButton.Text == "Hide" then
HideButton.Text = "Show"
TweenService:Create(HideButton, TweenInfo.new(0.4), {Position = UDim2.new(0.955, 0,0.013, 0)}):Play()
TweenService:Create(script.Parent.Header, TweenInfo.new(0.4), {Position = UDim2.new(1.1, 0, 0.011, 0)}):Play()
TweenService:Create(script.Parent.PlayerContainer, TweenInfo.new(0.4), {Position = UDim2.new(1.1, 0,0.051, 0)}):Play()
task.wait(0.05)
elseif HideButton.Text == "Show" then
HideButton.Text = "Hide"
TweenService:Create(HideButton, TweenInfo.new(0.4), {Position = UDim2.new(0.79, 0,0.013, 0)}):Play()
TweenService:Create(script.Parent.Header, TweenInfo.new(0.4), {Position = UDim2.new(0.825, 0, 0.011, 0)}):Play()
TweenService:Create(script.Parent.PlayerContainer, TweenInfo.new(0.4), {Position = UDim2.new(0.825, 0,0.051, 0)}):Play()
task.wait(0.05)
end
end
--= Initializers =--
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
for _, v in pairs(game.Players:GetChildren()) do
addPlayerToLeaderboard(v)
end
Players.PlayerAdded:Connect(function(plr)
addPlayerToLeaderboard(plr)
end)
HideButton.MouseButton1Click:Connect(handleVisibility)
Players.PlayerRemoving:Connect(function(plr)
for i, v in pairs(script.Parent.PlayerContainer:GetChildren()) do
if v and v.Name == plr.Name then
v:Remove()
break
end
end
end)