How do i make a arsenal leaderboard that cycles through the top kills every kill

alright so I have the ui for 10 sqaures for 10 players

but im wondering how do i cycle through everytime a player gets a kill?

2 Likes

Can you please elaborate on what you mean with cycle through everytime?

well lets say a kill is registered
i want the person with the highest kills to be in the front sqaure * the left sqaure *

So pretty much the Arsenal kills leaderboard?
It would just be a normal kills leaderboard but with just the images added on.

What script do you already have?
Maybe I can understand better.

i have no script
i haven’t worked with custom leaderboards in the past

Well why dont you do it 1 step at a time

  • Get Player ID’s
  • Set players count to 0
  • If kills someone set it to +1
  • whoever has the highest kills has the image of the farthest left

There are many ways you could do this.
Move the scripts for each player every time to parent it to the new players position. EX: players in third, scripts are parented under the 3rd GUI from the left, Player gets kill, script moves itself to 2nd Gui from left.
OR
Have a script that checks who has the most and just changes the number and image, rather than moving the scripts.

I hope you understand I can NOT just give you code.

For starters do you have a script that checks when someone kills someone and gets there name?
If not there are multiple tutorials on YouTube that could help you with this.

a fun way to do this would be to store every player’s kills in a dictionary and sort that dictionary to find the leaderboard position for each player

local playersKills = {
	["Player1"] = 5;
	["Player2"] = 2;
	["Player3"] = 4;
	["Player4"] = 4;
}

function findIndexWithValue(dictionaryToSearch, valueToSearch) --//used to find the player within the playersKill dictionary based on a killcount
	for index, value in pairs(dictionaryToSearch) do
		if value == valueToSearch then
			return index
		end
	end
end

local function shallowCopy(original) --//used to make a shallow copy of a dictionary
	local copy = {}
	for key, value in pairs(original) do
		copy[key] = value
	end

	return copy
end

function returnSortedArrayFromDictionary(dictionary) --//sorts the playersKills dictionary by converting the values into an array
	local sortedArray = {}

	for _, value in pairs(dictionary) do
		table.insert(sortedArray, tonumber(value))
	end

	table.sort(sortedArray, function(a,b)
		return a > b --//sorting from highest to lowest
	end)

	for index, key in ipairs(sortedArray) do
		sortedArray[index] = key
	end

	return sortedArray
end

function update()
	local tempDictionary = shallowCopy(playersKills) --//duplicates the playersKills dictionary in order to modify it without interrupting the base dictionary
	for position, value in ipairs(returnSortedArrayFromDictionary(tempDictionary)) do
		local index = findIndexWithValue(tempDictionary, value) --//receieve the index from value
		tempDictionary[index] = nil --//in order to make sure if multiple players have the same kills count the dictionary wouldn't ignore them by removing players that have already been sorted
		print(index, value)
        --//now you've got the player (index), their kills count (value) and their leaderboard position sorted from highest kills to lowest (position), you can now update the leaderboard accordingly 
	end
end

update()

you can call update() everytime someone gets a kill, I’m not sure how your leaderboard is structured so you’ll have to handle that aspect yourself, I’ve left comments in the code to instruct you on how to do so

2 Likes

Alternatively, a UIGridLayout could be used with a SortOrder of LayoutOrder. Then just assign your square’s LayoutOrder property to the amount of kills they have and the UIGridLayout will do the rest.

Just ensure your UIGridLayout has the correct properties, such as StartCorner being TopLeft and FillDirection as Horizontal.

2 Likes

ahh yes this is the thing i looking for

1 Like

Add a leaderstats variable called “Kills” to each player with a script:

local Players = game:GetService("Players")

local function leaderboardSetup(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local kills = Instance.new("IntValue")
	kills.Name = "Kills"
	kills.Parent = leaderstats	
	kills.Value = 0
end

-- Connect the "leaderboardSetup()" function to the "PlayerAdded" event
Players.PlayerAdded:Connect(leaderboardSetup)

Then parent the script above to ServerScriptService.

Next, to make the GUI update, you need to add an event in ReplicatedStorage.
Name this event “KillUpdate”
I am going to assume you know how to use events so I will move on.

Next you are going to want to use a script to see the order the players are in, by seeing how many kills each player has. If you want to put on a players icon, then you would use GetUserThumbnailAsync() to put on the photo. Here’s an example:

local userId = player.UserId
local picType = Enum.ThumbnailType.HeadShot
local picSize = Enum.ThumbnailSize.Size420x420 -- change numbers to the size of the picture
local content, isReady = Players:GetUserThumbnailAsync(userId, picType, picSize)

Then you can set the imageLabel to the profile picture by changing the .image property to equal content. The rest is up to you. Sorry if I misunderstood what you wanted explained, but I hope this helped!

2 Likes

updating every time the value changes should be good @RoyalTHEUSERNAME