How come my local scoreboard is not ranking correctly

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I am attempting to make my local scoreboard show the highest server based.

  1. What is the issue? Include screenshots / videos if possible!

It is not ranking correctly such as saying I am the highest while I have 0 and a second player has 100. I get no errors.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

i have tried many sorting methods but none seem to fix my issue.

here is my code

Remotes.Events.UpdateScoreboard.OnClientEvent:Connect(function(playerCoinsTable, playerKillsTable, playerGoldTable, playerKillstreakTable)	

	for _,v in pairs(ScoreboardUI.Main.Coins:GetChildren()) do
		if v:IsA("Frame") then
			v:Destroy()
		end
	end

	for _,v in pairs(ScoreboardUI.Main.Kills:GetChildren()) do
		if v:IsA("Frame") then
			v:Destroy()
		end
	end

	for _,v in pairs(ScoreboardUI.Main.GoldBars:GetChildren()) do
		if v:IsA("Frame") then
			v:Destroy()
		end
	end

	for _,v in pairs(ScoreboardUI.Main.Killstreak:GetChildren()) do
		if v:IsA("Frame") then
			v:Destroy()
		end
	end

	table.sort(playerCoinsTable, function(a, b)
		return a[2] > b[2]
	end)

	table.sort(playerKillsTable, function(a, b)
		return a[2] > b[2]
	end)

	table.sort(playerGoldTable, function(a, b)
		return a[2] > b[2]
	end)

	table.sort(playerKillstreakTable, function(a, b)
		return a[2] > b[2]
	end)

	for _,v in pairs(playerCoinsTable) do
		local CoinClone = ReplicatedStorage:WaitForChild("CoinTemplate"):Clone()
		CoinClone.Parent = ScoreboardUI.Main.Coins
		CoinClone.Amount.Text = Abbreviate(v[2])
		CoinClone.NameLabel.Text = v[1]
		
		local UserId = game.Players:GetUserIdFromNameAsync(v[1])
		
		local content, isReady = game.Players:GetUserThumbnailAsync(UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)

		CoinClone.PlayerIcon.Image = content
	end

	for _,v in pairs(playerKillsTable) do
		local KillsTemplate = ReplicatedStorage:WaitForChild("KillsTemplate"):Clone()
		KillsTemplate.Parent = ScoreboardUI.Main.Kills
		KillsTemplate.Amount.Text = Abbreviate(v[2]).." Kills"
		KillsTemplate.NameLabel.Text = v[1]

		local UserId = game.Players:GetUserIdFromNameAsync(v[1])
		
		local content, isReady = game.Players:GetUserThumbnailAsync(UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)

		KillsTemplate.PlayerIcon.Image = content
	end

	for _,v in pairs(playerGoldTable) do
		local GoldTemplate = ReplicatedStorage:WaitForChild("GoldTemplate"):Clone()
		GoldTemplate.Parent = ScoreboardUI.Main.GoldBars
		GoldTemplate.Amount.Text = Abbreviate(v[2])
		GoldTemplate.NameLabel.Text = v[1]

		local UserId = game.Players:GetUserIdFromNameAsync(v[1])
		
		local content, isReady = game.Players:GetUserThumbnailAsync(UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)

		GoldTemplate.PlayerIcon.Image = content
	end

	for _,v in pairs(playerKillstreakTable) do
		local StreakTemplate = ReplicatedStorage:WaitForChild("KillsTemplate"):Clone()
		StreakTemplate.Parent = ScoreboardUI.Main.Killstreak
		StreakTemplate.Amount.Text = Abbreviate(v[2]).." Kills"
		StreakTemplate.NameLabel.Text = v[1]

		local UserId = game.Players:GetUserIdFromNameAsync(v[1])
		
		local content, isReady = game.Players:GetUserThumbnailAsync(UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)

		StreakTemplate.PlayerIcon.Image = content
	end
end)

Couldn’t you just… switch the ‘>’ to a ‘<‘ in the table.Sort function

that doesnt really work as i want the highest to be top and lowest to be bottom and I just tested it with that and had no sucess

Is the list layout ordered by how they were placed in? That would work otherwise

Edit: I’m guessing it’s going off name if player2 is behind player1

let me check

30 charssssssssssss

wait that wouldnt help because in my code I delete all the UI elements an place each of them in seperately in the order of the table and since the list layout is set to layout order they should be place in order

huh, i mean layoutorder object. Unless you’re manually placing them by position, setting the list layout object to list them by index should fix this

Also, you only delete frames

thats what I am doing, the UIListLayour object is set layout order and it still doesnt work. also, the frames are deleted since I dont want the UIListLayout object to be deleted at runtime so I only delete the frames

1 Like

The only thing I could think of then is that you’re indexing the wrong value of the table to sort by. Try that.

Maybe try something like this?

function Sort(tabl)
	local buffer = {}
	for x=1,#tabl do
		local Highest = -math.huge
		for i,v in pairs(tabl) do
			if v[2] > Highest[2] then
				Highest = v
			end
		end
		buffer[x] = Highest
	end
	tabl = buffer
end
1 Like

You need to set the LayoutOrder of the Frame. Simply sorting the ListLayout by LayoutOrder wont do anything, since on default its 1. Try setting the LayoutOrder to the v[2] of your tables. Creating the Frames in order also won’t work, as sorting by LayoutOrder does not take into account the actual layout of the explorer tab, but LayoutOrder itself.