Server Leaderboard Ranking?

  1. What do you want to achieve?
    I’m trying to make a server leaderboard that shows the players in the server and who has the most money.

  2. What is the issue?
    So, I got the basic functionality of the board working but I don’t know how to make it sort the players so that whoever has the most gets on top.

  3. What solutions have you tried so far?
    I was thinking of using a table and sort that somehow to get the player with the most money but I don’t know if that would even work.

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)
2 Likes

maybe table.Sort() works?

3 Likes

You could use UIListLayout to order the elements of the leaderboard.

By settings the LayoutOrder of the frames inside the leaderboard, you can change the order the elements appear, first by setting the SortOrder from Name to LayoutOrder, and assigning each frame of the leaderboard a Layout order, the layout order of the individual frame should be the value you want to compare.

If you want the order of the leaderboard to be inverted, you can do:

frame.LayoutOrder = Money.Value -- which will order  the list so that the person with the lowest value is at the top
frame.LayoutOrder = 0-(Money.Value), -- which will order the list so that the person with highest value is at the top
2 Likes

That would help with the positioning but how would I make it so that they get #1 if they’re at the top and like #5 if they’re 5th on the list.

something like this

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder",player)
	leaderstats.Name = "leaderstats"
	
	local Money = Instance.new("IntValue",leaderstats)   -- name "money" whatever you want
	Money.Name = "Wins"  --  put your item here
	
	local x = Instance.new("IntValue",leaderstats)
	x.Name = "Kills"
	
	local y = Instance.new("IntValue",leaderstats)
	y.Name = "Coins"
end)

That’s leaderstats. I’m trying to make an actual board that shows the players in the server and their amount.

oh… Then sorry idk ;-;

30characters

You can use LayoutOrder or table.sort()

Using table.sort() would look like this

local playerValues = {}

table.insert(playerValues, {Player = player, Kills = killAmounts}) -- You should know where to iterate and assign these values to when the player joins.

table.sort(playerValues, function(a,b)
    return a.Kills < b.Kills
end

The playerValues is a table of each players kills. You would have to insert their kills when they join.
By the way, you also want to loop for each player thats already in the server and create a template for them, otherwise the player who joined wont see their stats.

1 Like

How do I get their rank text to change from like 5 to 1 though?

I believe the player who has the highest IntValue in the leaderboard would be the one who gets to the top, but I am not 100% sure if there’s an answer to your question.

But one way around this is just to try and make the IntValue that you want to highly prioritized to be extremely easy to get so players can get it way more than the other IntValues.