How would you make a "Most Kills" Script/Gui

Hello developers! I have a question, how would you make a “Most Kills” Script/Gui? Also, how would I show the player’s name and avatar? (I know I have already posted this topic before, but like nobody answered.) Anyway, I’m not asking for entire scripts, I just need the information, and the tools I need to make it. Thanks!

1 Like

There are many tutorials on youtube like this.

The reason people may not have replied is because this can be researched, Anyways, here’s how to do it:

Firstly, you need to iterate (go through) all of the players kills in the server and you want to sort that table.

then from there, you should have a sorted table. from there, you can make a leaderboard etc.

You should also check to see if any of the player’s values have changed or if a new player has joined the server.

function UpdateMostKills()
--Do the updating
end

game.Players.PlayerAdded:Connect(function()
UpdateMostKills()
end

game.Players.PlayerRemoving:Connect(function()
UpdateMostKills()
end

game.ReplicatedStorage.ValueChanged.OnServerEvent:Connect(function(plr, newval)
if plr.Kills.Value ~= newval then
UpdateMostKills()
end
end
1 Like

No, I meant like after a round, it will show who got the most kills and it shows the player and avatar

1 Like

Can you show your round script?

Ohh after a round, That’s simpler then.

At the end of the round, you go through all the player’s values. Sort it then you’ve got the most kills.

Their kills reset at the end of the sorting.

local KillsTable = {}

function SortKills()
for i, v in pairs(game.Players:GetChildren()) do
table.insert(KillsTable, v.Kills.Value)
end

--then do table.sort here
end


--when round ends
SortKills()
--then set all the players kills to 0

For the comment that says, “then do table.sort” do you sort all the players kills from least to greatest?

Yes, you do, you just alter the table.sort function a bit to do that.

How would you do that? (I already have a working leaderstats for the kills)

table.sort(KillsTable, function(a,b)

return a < b

end)

This is how you would do it, if you want to sort the table, that will sort from lowest to highest, to switch the order, you do a > b instead of a < b

Yeah but in a game, there could be more that 2 people.(How would you fix it so it is compatible to all servers with different amounts of players?)

That should work with any numbers, it will sort all of the player’s kills that are present at the end of the round. Do you simply just want to get the one person with the most kills or do you want to create a leaderboard?

I am currently hiring a developer to do this, but we are stumped about how to execute it, because players can farm an afk alt or something.

Just the one person who got the most kills.

Ah that’s simple you just do this:

function GetPersonWithMostKills()
local current, plr = 0, nil

for i, v in pairs(game.Players:GetChildren()) do
if v.Kills.Value > current then
plr = v
end
end

return plr
end

--when round ends
PlayerWithMostKills = GetPlayerWithMostKills()
1 Like

So this gets the player with the most kills?

1 Like

Yes it would, that’s a very basic interpretation of it though. if you have leaderstats, v.Kills.Value becomes v.leaderstats.Kills.Value since what you’re doing is Player.leaderstats.Kills.Value

Wait ok, so how would you show that player’s avatar and their name?

You can Simply do PlayerWithMostKills.Name

and to get their avatar you want to reffer to this thread

In your script what is the GetPlayerWithMostKills function? Also, what is PlayerWithMostKills? (They are both not defined)