How to make FFA system

So i want to make an arsenal similar system where if someone kills you see who has the most kills.
I tried to make an int number to the player but i have no idea how to sort it and i need some help

like that

here is the script that i tried:

local Timer = game.ReplicatedStorage.Events.RoundEvents:WaitForChild("Timer")
local InRound = game.ReplicatedStorage.Round:WaitForChild("InRound") -- BoolValue from Round
local KillEvent = game.ReplicatedStorage.Events.FPS:WaitForChild("KillEvent")

local Playertable = {}

InRound.Changed:Connect(function(Val)
	if Val == true then
		print("round start")

	elseif Val == false then
		print("round over")
		table.clear(Playertable)
		local players = game.Players
		for i, v in players:GetChildren() do
			for i, e in v:GetChildren() do
				if e.Name == "Kills" then
					e.Value = 0
				end
			end
		end		
	end

end)

game.Players.PlayerAdded:Connect(function(plr)
	local Kills = Instance.new("IntValue")
	Kills.Name = "Kills"
	Kills.Parent = plr
	Kills.Value = 0
end)


KillEvent.Event:Connect(function(plr)
	if InRound.Value == true then
		local Kills = plr.Kills

		Kills.Value += 1
		print(Kills.Value)
	end
end)

You can use table.sort. Here’s an example:

local Players = game:GetService("Players")

local function getKills(player: Player): number
    return if player:FindFirstChild("leaderstats") ~= nil and player.leaderstats:FindFirstChild("Kills") ~= nil then player.leaderstats.Kills.Value else 0
end

local function getSortedPlayersByKills(): {Player}
    local players: {Player} = Players:GetPlayers()

    table.sort(players, function(playerA: Player, playerB: Player): boolean
        return getKills(playerA) > getKills(playerB)
    end)

    return players
end

for placement: number, player: Player in getSortedPlayerByKills() do
    local kills: number = getKills(player)

    -- code
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.