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

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)

You have to define them both…

local PlayerWithMostKills

then set it later.

The function you just simply change the name to match,

function GetPlayerWithMostKills()

GetPlayerWithMostKills()

'''
      function GetPlayerWithMostKills()
      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()

print(player.Name)

      '''

something like this?

Would this print the players name, if they get the most kills?

Also, how would you show the player who got the most kills avatar? (I already have a script for showing the avatar. But I need it to show if the player got the most kills, and if the round is over)


This is what the kills Gui looks like

Is it normal to print nil if you don’t kill anyone?