Help with getting the player with highest amount of kills

Ok, ok. Before I start, yes I know there are a lot of posts regarding this but unfortunately I’m unable to understand those.

Hey there all! So, I’m making an FPS game, and I’m kinda stuck at this part. I don’t know how to get the player with the highest amount of kills. Any type of help will be appreciated, thanks!

Extra Info:

  1. Status is a StringValue inside a folder named ‘Values’ in ReplicatedStorage.
  2. CurrentGamemode is another StringValue in the same place as Status.
  3. PlayerContainer is a separate folder in ReplicatedStorage in which, when a player clicks “Deploy” he’ll spawn in the game and a StringValue named as the player will be added to the folder.
Code
Status.Changed:Connect(function(NewVal)
	if NewVal == "Round" then
		CurrentGamemode.Changed:Connect(function(NewVal2)
			if NewVal2 == "Deathmatch" then
				local plrs = {}
				
				local function OnPlayerContainerAdded(child)
					if Players:FindFirstChild(child.Name) then
						local FoundPlayer = Players:FindFirstChild(child.Name)
						
						table.insert(plrs, {
							["Player"] = FoundPlayer;
							["Kills"] = FoundPlayer:WaitForChild("NonSaveInfo"):WaitForChild("Kills")
						})
						
						print(plrs[1]["Player"].Name)
					end
				end
				
				PlayerContainer.ChildAdded:Connect(OnPlayerContainerAdded)
				
				for _, v in ipairs(PlayerContainer:GetChildren()) do
					OnPlayerContainerAdded(v)
				end
				
				local Highest = nil
				
				table.sort(plrs, function(a, b)
					return a["Kills"].Value > b["Kills"].Value
				end)
				
				for _, v in pairs(plrs) do
					v["Kills"].Changed:Connect(function(x)
						print(tostring(x))
						
						Highest = v["Kills"].Value
						
						if x == 20 then
							print(string.format(("%s has won the game!"), v["Player"].Name))
						end
					end)
				end
			end
		end)
	end
end)
1 Like

Are there any errors with the code you provided?

Are there any errors with the code
You can check this by going on Roblox studio and running the script

Considering that probably isn’t the whole code most likely, it wouldn’t work and OP can just tell me what the error is. Late reply due to OP not replying.

Nope. No errors at all. A smaller way to explain what I want to achieve is to sort tables inside of that table. Meaning:

local Table1 = {
    {
        ["Kills"] = 23
    }
}

Something like this, if you get what I mean.