How to sort kills in a round

So i want to make a round system and the thing is i want to make a FFA system.

I made already the kill trigger and it saves it, but i want to sort the kills and player name in a table as both values at once.
I made it kinda but idk how to update the value/sort the values so the gui updates(there is no gui script)

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 == "KillsR" then
					e.Value = 0
				end
			end
		end		
	end
	
end)

game.Players.PlayerAdded:Connect(function(plr)
	local KillsRound = Instance.new("IntValue") -- makes a intValue so i can accses it
	KillsRound.Name = "KillsR"
	KillsRound.Parent = plr
	table.insert(Playertable, {plr, KillsRound.Value})
end)


KillEvent.Event:Connect(function(plr)
	if InRound.Value == true then
		local Kills = plr.KillsR
		
		for i,v in Playertable do
			local PlayerT = table.find(v, plr)
			print(PlayerT)
			for i, e in PlayerT:GetChildren() do
				if e:IsA("IntValue") then

					Kills.Value += 1
					e = Kills.Value
				end
			end
				
			
		end
	end
end)
1 Like

Take a look at the sorting function for tables: table | Documentation - Roblox Creator Hub

You can sort by kills by doing something like the following:

-- A and B represent entries in the Playertable array. i.e. of the form { Player, Kills }
table.sort(Playertable, function(A, B)
    return A[2] < B[2]
end)
2 Likes

Sorry for late reply
how do i update the values, because i wanna do a gui which shows the players kills

The code I posted will update the table values themselves. To update the UI, it depends on how you’re implementing it.

In my experience, I often have events that fire whenever the game state changes. The UI code listens for these events and updates itself based on the new game state. This could be as simple as using a BindableEvent and passing in the updated Playertable when you fire the event. Your UI code will connect to this event and update itself whenever the event fires.

hmm alrr (sry i wasnt checking forum)

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