Highest kills problem

i have my deathmatch gamemode on my game and it didnt work properly
the only problem is to get a player get the highest kills and get displayed in the UI
Example :
image
is there a way to do this, let me know!
error:

The way I would do it is by running a loop on all player instances and comparing the last highest to the current player being checked.
For example:

local players = game:GetService("Players") -- Get game.Players
local mostKills = { -- store current mostkills and the corresponding plr instance
  count = 0,
  plr = nil
}

for index, plr in pairs(players:GetPlayers()) do -- Run through all players
  if plr:FindFirstChild('leaderstats'):FindFirstChild('Kills').Value > mostKills.count then -- Check if their kill count is above mostKills.count
    mostKills.count = plr.leaderstats.Kills.Value -- Set new highest kill count
    mostKills.plr = plr -- set corresponding player
  end
end

print(mostKills.count) -- Get the highest kills
print(mostKills.plr) -- Get the corresponding player

i am sorry, but your method is not working
reason : didnt get plr on mostkills

Please post your code so we can see exactly what’s wrong with it.

local mostKills = { -- store current mostkills and the corresponding plr instance
			count = 0,
			plr = nil
		}
		
		local highestValue = Instance.new("ObjectValue", rep)
		highestValue.Name = "HIGHEST KILLS"
		
		for index, plr in pairs(plrs:GetPlayers()) do -- Run through all players
			if plr:FindFirstChild("leaderstats"):FindFirstChild("Kills").Value > mostKills.count then -- Check if their kill count is above mostKills.count
				mostKills.count = plr.leaderstats.Kills.Value -- Set new highest kill count
				mostKills.plr = plr -- set corresponding player
				highestValue.Value = plr
			end
		end
		
		local gameStart = tick()

		while true do
			game:GetService("RunService").Heartbeat:Wait()

			local timeLeft = DMconfig.RoundTime - math.round((tick() - gameStart))
			local mins = math.floor(timeLeft / 60)
			local secs = timeLeft - (mins * 60)
			if string.len(secs) < 2 then
				secs = "0" .. tostring(secs)
			end
			if string.len(mins) < 2 then
				mins = "0" .. tostring(mins)
			end
			statusValue.Value = mins .. ":" .. secs
			if timeLeft <= 0 then
				break
			end
		end
		if highestValue.Value then
			statusValue.Value = highestValue.Value.Name.." WINS!"
		else
			statusValue.Value = "STALEMATE!"
		end

		for i, plr in pairs(game.Players:GetPlayers()) do
			plr.Team = nil
			plr:LoadCharacter()
			plr:WaitForChild("leaderstats"):WaitForChild("Kills").Value = 0
			plr:WaitForChild("leaderstats"):WaitForChild("KillStreak").Value = 0
		end	

		roundSetup.inRound.Value = false
		mapClone:Destroy()
		highestValue:Destroy()

the code is only the deathmatch part

Is this the ServerScriptService.Scripts.RoundSystem script? I need that code because that’s where the problem lies.

yes it is, heres the full code:

--// Service's //--

local plrs = game:GetService("Players")
local rep = game:GetService("ReplicatedStorage")
local ss = game:GetService("ServerStorage")
local Teams = game:GetService("Teams")

--// Settings //--

local roundSetup = {
	inRound = rep.InRound
}

--// Variables //--

local events = rep.Remotes:WaitForChild("Events")
local functions = rep.Remotes:WaitForChild("Functions")
local lobbySpawn = game.Workspace.lobbySpawn
local maps = rep.Maps:GetChildren()
local items = ss:WaitForChild("Items")
local flag = rep:WaitForChild("Flag"):WaitForChild("Flag")
local votingSystem = game.Workspace.Voting
local TDMconfig = require(rep.ModuleScripts:WaitForChild("TDM_CONFIGURATION"))
local CTFconfig = require(rep.ModuleScripts:WaitForChild("CTF_CONFIGURATION"))
local DMconfig = require(rep.ModuleScripts:WaitForChild("DM_CONFIGURATION"))

local statusValue = Instance.new("StringValue")
statusValue.Name = "STATUS"
statusValue.Parent = rep

local choices = votingSystem:GetChildren()

local isAnOption
local randomMap

local chosenMap
local mapClone

local Team1 = "RED"
local Team2 = "BLU"

local bluTeam
local redTeam

-- events
local getItemsEvent = events:WaitForChild("GetItems")
local inMenuEvent = events:WaitForChild("InMenuEvent")
local changeHighest = events:WaitForChild("ChangeHighest")

--// Main Code //--

function rewardWinner(team)
	statusValue.Value = team.Name.." WINS!"

	--for i, plr in pairs(team:GetPlayers()) do
	--	plr.leaderstats.Cash.Value += TDMconfig.WinReward
	--end
end

function chosenGamemode()
	if mapClone then
		if mapClone:WaitForChild("Gamemode").Value == "Team Deathmatch" then
			print("tdm")
			if not Teams:FindFirstChild(Team1) then
				bluTeam = Instance.new("Team", Teams)
				bluTeam.Name = Team2
				bluTeam.TeamColor = BrickColor.new("Deep blue")
				bluTeam.AutoAssignable = false

				redTeam = Instance.new("Team", Teams)
				redTeam.Name = Team1
				redTeam.TeamColor = BrickColor.new("Bright red")
				redTeam.AutoAssignable = false
			end
			local RedSpawns = mapClone.redSpawns:GetChildren()
			local BluSpawns = mapClone.bluSpawns:GetChildren()

			local randomRedSpawn = RedSpawns[math.random(1,#RedSpawns)]
			local randombluSpawn = BluSpawns[math.random(1,#BluSpawns)]

			local teams = {redTeam, bluTeam}

			for _, player in pairs(plrs:GetPlayers()) do
				local char = player.Character
				if #redTeam:GetPlayers() > #bluTeam:GetPlayers() then
					player.Team = bluTeam
					char.HumanoidRootPart.CFrame = CFrame.new(randombluSpawn.Position + Vector3.new(math.random(1,3),math.random(1,3),math.random(1,3)))
				elseif #redTeam:GetPlayers() < #bluTeam:GetPlayers() then
					player.Team = redTeam
					char.HumanoidRootPart.CFrame = CFrame.new(randomRedSpawn.Position + Vector3.new(math.random(1,3),math.random(1,3),math.random(1,3)))
				else
					player.Team = teams[math.random(1, #teams)]
					if player.Team == redTeam then
						char.HumanoidRootPart.CFrame = CFrame.new(randomRedSpawn.Position + Vector3.new(math.random(1,3),math.random(1,3),math.random(1,3)))
					else
						char.HumanoidRootPart.CFrame = CFrame.new(randombluSpawn.Position + Vector3.new(math.random(1,3),math.random(1,3),math.random(1,3)))
					end
				end
			end
		elseif mapClone:WaitForChild("Gamemode").Value == "Capture The Flag" then
			print("steal the flag")
			if not Teams:FindFirstChild(Team1) then
				bluTeam = Instance.new("Team", Teams)
				bluTeam.Name = Team2
				bluTeam.TeamColor = BrickColor.new("Deep blue")
				bluTeam.AutoAssignable = false

				redTeam = Instance.new("Team", Teams)
				redTeam.Name = Team1
				redTeam.TeamColor = BrickColor.new("Bright red")
				redTeam.AutoAssignable = false
			end
			local RedSpawns = mapClone.redSpawns:GetChildren()
			local BluSpawns = mapClone.bluSpawns:GetChildren()

			local randomRedSpawn = RedSpawns[math.random(1,#RedSpawns)]
			local randombluSpawn = BluSpawns[math.random(1,#BluSpawns)]

			local teams = {redTeam, bluTeam}
			
			for _, player in pairs(plrs:GetPlayers()) do
				local char = player.Character
				if #redTeam:GetPlayers() > #bluTeam:GetPlayers() then
					player.Team = bluTeam
					char.HumanoidRootPart.CFrame = CFrame.new(randombluSpawn.Position + Vector3.new(math.random(1,3),math.random(1,3),math.random(1,3)))
				elseif #redTeam:GetPlayers() < #bluTeam:GetPlayers() then
					player.Team = redTeam
					char.HumanoidRootPart.CFrame = CFrame.new(randomRedSpawn.Position + Vector3.new(math.random(1,3),math.random(1,3),math.random(1,3)))
				else
					player.Team = teams[math.random(1, #teams)]
					if player.Team == redTeam then
						char.HumanoidRootPart.CFrame = CFrame.new(randomRedSpawn.Position + Vector3.new(math.random(1,3),math.random(1,3),math.random(1,3)))
					else
						char.HumanoidRootPart.CFrame = CFrame.new(randombluSpawn.Position + Vector3.new(math.random(1,3),math.random(1,3),math.random(1,3)))
					end
				end
			end
		elseif mapClone:WaitForChild("Gamemode").Value == "Deathmatch" then
			print("most kills")
			for _, player in pairs(plrs:GetPlayers()) do
				local char = player.Character
				local plrSpawns = mapClone.Spawns:GetChildren()
				local randomplrSpawn = plrSpawns[math.random(1,#plrSpawns)]
				
				char.HumanoidRootPart.CFrame = CFrame.new(randomplrSpawn.Position + Vector3.new(math.random(1,3),math.random(1,3),math.random(1,3)))
			end
		end
	end
end

function PickRandomMap()
	local randomNumber = math.random(1, #maps)
	randomMap = maps[randomNumber]

	return randomMap.CanBeVoted
end

for i, choice in pairs(choices) do

	local name = choice.label.SurfaceGui.TextLabel
	local picture = choice.Image.SurfaceGui.ImageLabel

	isAnOption = PickRandomMap()

	if isAnOption.Value == true then
		repeat 
			isAnOption = PickRandomMap()
		until
		isAnOption.Value == false
		name.Text = randomMap.Name
		picture.Image = randomMap.Image.Value
		randomMap.CanBeVoted.Value = true

	else
		name.Text = randomMap.Name
		picture.Image = randomMap.Image.Value
		randomMap.CanBeVoted.Value = true		
	end					
end	

function getItems(plr)
	for i = 1, 1, 1 do
		--melee(first item slot)
		while true do
			local rng = math.random(1, #items.Melee:GetChildren())
			local rngItem = items.Melee:GetChildren()[rng]

			if not plr.Backpack:FindFirstChild(rngItem.Name) then
				rngItem:Clone().Parent = plr.Backpack
				break
			end
		end
		task.wait(0.1)
		--projectiles(second item slot)
		while true do
			local rng = math.random(1, #items.Projectiles:GetChildren())
			local rngItem = items.Projectiles:GetChildren()[rng]

			if not plr.Backpack:FindFirstChild(rngItem.Name) then
				rngItem:Clone().Parent = plr.Backpack
				break
			end
		end
		task.wait(0.1)
		--special(third item slot)
		while true do
			local rng = math.random(1, #items.Special:GetChildren())
			local rngItem = items.Special:GetChildren()[rng]

			if not plr.Backpack:FindFirstChild(rngItem.Name) then
				rngItem:Clone().Parent = plr.Backpack
				break
			end
		end
	end
end

function removeItems(plr, hum)
	hum:UnequipTools()
	plr.Backpack:ClearAllChildren()
end

getItemsEvent.OnServerEvent:Connect(function(plr)
	local char = plr.Character or plr.CharacterAdded:Wait()
	if not char:WaitForChild("InMenu").Value then
		getItems(plr)
	end
end)

inMenuEvent.OnServerEvent:Connect(function(plr, value)
	local char = plr.Character or plr.CharacterAdded:Wait()
	char:WaitForChild("InMenu").Value = value
end)

roundSetup.inRound.Changed:Connect(function()
	if roundSetup.inRound.Value == true then
		for i, plr in pairs(game.Players:GetPlayers()) do
			local char = plr.Character
			local hum = char:WaitForChild("Humanoid")

			if not char:WaitForChild("InMenu").Value then
				getItems(plr)
			end	
		end
	else
		for i, plr in pairs(game.Players:GetPlayers()) do
			local char = plr.Character
			local hum = char:WaitForChild("Humanoid")

			removeItems(plr, hum)
			mapClone:Destroy()

			for i, map in pairs(maps) do
				map.CanBeVoted.Value = false
			end

			for i, choice in pairs(choices) do

				local name = choice.label.SurfaceGui.TextLabel
				local picture = choice.Image.SurfaceGui.ImageLabel

				isAnOption = PickRandomMap()

				if isAnOption.Value == true then
					repeat 
						isAnOption = PickRandomMap()
					until
					isAnOption.Value == false
					name.Text = randomMap.Name
					picture.Image = randomMap.Image.Value
					randomMap.CanBeVoted.Value = true

				else
					name.Text = randomMap.Name
					picture.Image = randomMap.Image.Value
					randomMap.CanBeVoted.Value = true		
				end					
			end	
		end
	end
end)

-- main round system
while true do
	for i, plr in pairs(game.Players:GetPlayers()) do
		for i, v in pairs(plr.Backpack:GetChildren()) do
			if v then
				removeItems(plr, plr.Character:WaitForChild("Humanoid"))
			end
		end
	end
	lobbySpawn.Neutral = true
	local plrsInGame = {}
	while true do
		plrsInGame = {}
		for i, plr in pairs(game.Players:GetPlayers()) do
			if plr.Character and plr.Character.Humanoid.Health > 0 then
				table.insert(plrsInGame, plr)
			end
		end

		if #plrsInGame >= 2 then
			break
		else
			local neededPlayers = 2 - #plrsInGame
			statusValue.Value = "Waiting for " .. neededPlayers .. " more player" .. (neededPlayers ~= 1 and "s" or "")

			task.wait(1)
		end
	end
	for i = TDMconfig.IntermissionTime, 0, -1 do
		statusValue.Value = "Intermission..("..i..")"
		task.wait(1)
	end
	local Choice1Votes = #votingSystem.Choice1.button.Votes:GetChildren()
	local Choice2Votes = #votingSystem.Choice2.button.Votes:GetChildren()
	local Choice3Votes = #votingSystem.Choice3.button.Votes:GetChildren()

	if Choice1Votes >= Choice2Votes and Choice1Votes >= Choice3Votes then
		chosenMap = votingSystem.Choice1.label.SurfaceGui.TextLabel.Text
	elseif Choice2Votes >= Choice1Votes and Choice2Votes >= Choice3Votes then
		chosenMap = votingSystem.Choice2.label.SurfaceGui.TextLabel.Text
	else
		chosenMap = votingSystem.Choice3.label.SurfaceGui.TextLabel.Text
	end
	--	--- getting the map from the replicated storgae to the workspace

	for i, map in pairs(maps) do
		if chosenMap == map.Name then
			mapClone = map:Clone()
			mapClone.Parent = game.Workspace
		end
	end

	statusValue.Value = "MAP: " .. mapClone.Name
	chosenGamemode()
	lobbySpawn.Neutral = false
	task.wait(3)
	for i = TDMconfig.MapWaitTime, 0, -1 do
		statusValue.Value = "Round starts in "..i.." seconds"
		task.wait(1)
	end
	roundSetup.inRound.Value = true
	if mapClone:WaitForChild("Gamemode").Value == "Team Deathmatch" then
		local teamKillsFolder = Instance.new("Folder")
		teamKillsFolder.Name = "TEAM KILLS"
		teamKillsFolder.Parent = rep

		local team1Kills = Instance.new("IntValue")
		team1Kills.Name = "TEAM 1"
		team1Kills.Parent = teamKillsFolder

		local team2Kills = Instance.new("IntValue")
		team2Kills.Name = "TEAM 2"
		team2Kills.Parent = teamKillsFolder
		
		local team1 = game.Teams:FindFirstChild("RED")
		local team2 = game.Teams:FindFirstChild("BLU")
		
		local RedSpawns = mapClone.redSpawns:GetChildren()
		local BluSpawns = mapClone.bluSpawns:GetChildren()

		local randomRedSpawn = RedSpawns[math.random(1,#RedSpawns)]
		local randombluSpawn = BluSpawns[math.random(1,#BluSpawns)]

		for i, plr in pairs(game.Players:GetPlayers()) do

			local char = plr.Character
			if char and char.Humanoid.Health > 0 then
				local connection1 = char.Humanoid.Died:Connect(function()
					if plr.Team == team1 then
						team2Kills.Value += 1
					elseif plr.Team == team2 then
						team1Kills.Value += 1
					end
				end)

				local connection3 = nil
				local connection2 = plr.CharacterAdded:Connect(function(newChar)
					local hum = newChar:WaitForChild("Humanoid")

					if plr.Team == team1 then
						newChar.HumanoidRootPart:GetPropertyChangedSignal("CFrame"):Wait()
						newChar.HumanoidRootPart.CFrame = CFrame.new(randomRedSpawn.Position + Vector3.new(math.random(1,3),math.random(1,3),math.random(1,3)))
					elseif plr.Team == team2 then
						newChar.HumanoidRootPart:GetPropertyChangedSignal("CFrame"):Wait()
						newChar.HumanoidRootPart.CFrame = CFrame.new(randombluSpawn.Position) + Vector3.new(math.random(1,3),math.random(1,3),math.random(1,3))
					end

					connection3 = hum.Died:Connect(function()
						if plr.Team == team1 then
							team2Kills.Value += 1
						elseif plr.Team == team2 then
							team1Kills.Value += 1
						end
					end)
				end)

				teamKillsFolder.Destroying:Connect(function()
					connection1:Disconnect()
					connection2:Disconnect()
					connection3:Disconnect()
				end)
			end
		end
		local gameStart = tick()

		while true do

			local now = tick()
			local timeLeft = TDMconfig.RoundTime - math.round(now - gameStart)

			local mins = math.floor(timeLeft / 60)
			local secs = timeLeft - (mins * 60)
			if string.len(secs) < 2 then
				secs = "0" .. tostring(secs)
			end
			if string.len(mins) < 2 then
				mins = "0" .. tostring(mins)
			end

			statusValue.Value = mins .. ":" .. secs


			if timeLeft <= 0 or #team1:GetPlayers() < 1 or #team2:GetPlayers() < 1 then

				if team1Kills.Value > team2Kills.Value then
					rewardWinner(team1)
				elseif team2Kills.Value > team1Kills.Value then
					rewardWinner(team2)
				else
					statusValue.Value = "STALEMATE!"
				end
				break

			elseif TDMconfig.StopOnceKillsReached then

				if team1Kills.Value >= TDMconfig.KillsRequiredToStop then
					rewardWinner(team1)
					break

				elseif team2Kills.Value >= TDMconfig.KillsRequiredToStop then
					rewardWinner(team2)
					break
				end
			end

			game:GetService("RunService").Heartbeat:Wait()
		end
		
		for i, plr in pairs(game.Players:GetPlayers()) do
			plr.Team = nil
			plr:LoadCharacter()
			plr:WaitForChild("leaderstats"):WaitForChild("Kills").Value = 0
			plr:WaitForChild("leaderstats"):WaitForChild("KillStreak").Value = 0
		end	

		roundSetup.inRound.Value = false
		for i, v in pairs(game.Teams:GetChildren()) do
			if v then
				v:Destroy()
			end
		end
		mapClone:Destroy()
		teamKillsFolder:Destroy()

		task.wait(TDMconfig.RoundFinishedTime)
	elseif mapClone:WaitForChild("Gamemode").Value == "Capture The Flag" then
		local team1 = game.Teams:FindFirstChild("RED")
		local team2 = game.Teams:FindFirstChild("BLU")
		for i, plr in pairs(game.Players:GetPlayers()) do
			local char = plr.Character

			local RedSpawns = mapClone.redSpawns:GetChildren()
			local BluSpawns = mapClone.bluSpawns:GetChildren()

			local randomRedSpawn = RedSpawns[math.random(1,#RedSpawns)]
			local randombluSpawn = BluSpawns[math.random(1,#BluSpawns)]
			
			local connection = plr.CharacterAdded:Connect(function(newChar)
				local newHRP = newChar:WaitForChild("HumanoidRootPart")
				if plr.Team == team1 then
					newHRP.HumanoidRootPart:GetPropertyChangedSignal("CFrame"):Wait()
					newHRP.HumanoidRootPart.CFrame = CFrame.new(randomRedSpawn.Position + Vector3.new(math.random(1,3),math.random(1,3),math.random(1,3)))
				elseif plr.Team == team2 then
					newHRP.HumanoidRootPart:GetPropertyChangedSignal("CFrame"):Wait()
					newHRP.HumanoidRootPart.CFrame = CFrame.new(randombluSpawn.Position) + Vector3.new(math.random(1,3),math.random(1,3),math.random(1,3))
				end
			end)

			mapClone.Destroying:Connect(function()
				connection:Disconnect()
			end)
		end
		local team1FlagSpawn = mapClone.FlagRedSpawn
		local team2FlagSpawn = mapClone.FlagBluSpawn

		local team1Flag = flag:Clone()
		team1Flag.Base.Color = team1.TeamColor.Color
		team1Flag.FlagModel.Flag.Color = team1.TeamColor.Color
		team1Flag:SetPrimaryPartCFrame(team1FlagSpawn.CFrame * CFrame.Angles(0, 0, math.rad(-90)))
		team1Flag.Parent = mapClone

		local team2Flag = flag:Clone()
		team2Flag.Base.Color = team2.TeamColor.Color
		team2Flag.FlagModel.Flag.Color = team2.TeamColor.Color
		team2Flag:SetPrimaryPartCFrame(team2FlagSpawn.CFrame * CFrame.Angles(0, 0, math.rad(-90)))
		team2Flag.Parent = mapClone
		
		local scoresFolder = Instance.new("Folder")
		scoresFolder.Name = "SCORES"
		scoresFolder.Parent = rep

		local team1Score = Instance.new("IntValue")
		team1Score.Name = "TEAM 1 SCORE"
		team1Score.Parent = scoresFolder
		local team2Score = Instance.new("IntValue")
		team2Score.Name = "TEAM 2 SCORE"
		team2Score.Parent = scoresFolder

		local flag1Taken = false
		local flag2Taken = false
		team1Flag.Base.Touched:Connect(function(hit)

			local charTouched = hit.Parent
			local plrTouched = game.Players:GetPlayerFromCharacter(charTouched)
			if plrTouched and plrTouched.Team == team2 and charTouched.Humanoid.Health > 0 and not flag1Taken then
				flag1Taken = charTouched

				local flagOnBack = team1Flag.FlagModel:Clone()
				for i, desc in pairs(flagOnBack:GetDescendants()) do
					if desc:IsA("BasePart") then
						desc.CanCollide = false
						desc.Anchored = false

						if desc ~= flagOnBack.PrimaryPart then
							local wc = Instance.new("WeldConstraint")
							wc.Part0 = flagOnBack.PrimaryPart
							wc.Part1 = desc
							wc.Parent = flagOnBack.PrimaryPart
						end
					end
				end
				local torso = charTouched:FindFirstChild("UpperTorso") or charTouched:FindFirstChild("Torso") or charTouched.HumanoidRootPart
				flagOnBack:SetPrimaryPartCFrame((torso.CFrame - torso.CFrame.LookVector/2) * CFrame.Angles(0, 0, math.rad(-90)))
				local wc = Instance.new("WeldConstraint")
				wc.Part0 = torso
				wc.Part1 = flagOnBack.PrimaryPart
				wc.Parent = flagOnBack

				flagOnBack.Name = "FLAG"
				flagOnBack.Parent = charTouched

				for i, desc in pairs(team1Flag.FlagModel:GetDescendants()) do
					if desc:IsA("BasePart") then
						desc.Transparency = 1
						desc.CanCollide = false
					end
				end

				charTouched.Humanoid.Died:Wait()
				if flag1Taken == charTouched then
					flag1Taken = false

					for i, desc in pairs(team1Flag.FlagModel:GetDescendants()) do
						if desc:IsA("BasePart") then
							desc.Transparency = 0
						end
					end
				end

			elseif flag2Taken == charTouched and charTouched.Humanoid.Health > 0  and plrTouched.Team == team1 then
				flag2Taken = false
				charTouched["FLAG"]:Destroy()
				team1Score.Value += 1
				for i, desc in pairs(team2Flag.FlagModel:GetDescendants()) do
					if desc:IsA("BasePart") then
						desc.Transparency = 0
						desc.CanCollide = false
					end
				end
			end
		end)	

		team2Flag.Base.Touched:Connect(function(hit)

			local charTouched = hit.Parent
			local plrTouched = game.Players:GetPlayerFromCharacter(charTouched)
			if plrTouched and plrTouched.Team == team1 and charTouched.Humanoid.Health > 0 and not flag2Taken then
				flag2Taken = charTouched

				local flagOnBack = team2Flag.FlagModel:Clone()
				for i, desc in pairs(flagOnBack:GetDescendants()) do
					if desc:IsA("BasePart") then
						desc.CanCollide = false
						desc.Anchored = false

						if desc ~= flagOnBack.PrimaryPart then
							local wc = Instance.new("WeldConstraint")
							wc.Part0 = flagOnBack.PrimaryPart
							wc.Part1 = desc
							wc.Parent = flagOnBack.PrimaryPart
						end
					end
				end
				local torso = charTouched:FindFirstChild("UpperTorso") or charTouched:FindFirstChild("Torso") or charTouched.HumanoidRootPart
				flagOnBack:SetPrimaryPartCFrame((torso.CFrame - torso.CFrame.LookVector/2) * CFrame.Angles(0, 0, math.rad(-90)))
				local wc = Instance.new("WeldConstraint")
				wc.Part0 = torso
				wc.Part1 = flagOnBack.PrimaryPart
				wc.Parent = flagOnBack

				flagOnBack.Name = "FLAG"
				flagOnBack.Parent = charTouched

				for i, desc in pairs(team2Flag.FlagModel:GetDescendants()) do
					if desc:IsA("BasePart") then
						desc.Transparency = 1
					end
				end

				charTouched.Humanoid.Died:Wait()
				if flag2Taken == charTouched then
					flag2Taken = false

					for i, desc in pairs(team2Flag.FlagModel:GetDescendants()) do
						if desc:IsA("BasePart") then
							desc.Transparency = 0
						end
					end
				end

			elseif flag1Taken == charTouched and charTouched.Humanoid.Health > 0 and plrTouched.Team == team2 then
				flag1Taken = false
				charTouched["FLAG"]:Destroy()
				team2Score.Value += 1
				for i, desc in pairs(team1Flag.FlagModel:GetDescendants()) do
					if desc:IsA("BasePart") then
						desc.Transparency = 0
						desc.CanCollide = false
					end
				end
			end
		end)
		local gameStart = tick()

		while true do
			game:GetService("RunService").Heartbeat:Wait()

			local timeLeft = CTFconfig.RoundTime - math.round((tick() - gameStart))
			local mins = math.floor(timeLeft / 60)
			local secs = timeLeft - (mins * 60)
			if string.len(secs) < 2 then
				secs = "0" .. tostring(secs)
			end
			if string.len(mins) < 2 then
				mins = "0" .. tostring(mins)
			end
			statusValue.Value = mins .. ":" .. secs

			numPlrs = 0
			for i, plr in pairs(game.Players:GetPlayers()) do
				if plr then
					numPlrs += 1
				end
			end
			if numPlrs < CTFconfig.MinimumPlayersRequired then
				break

			elseif CTFconfig.StopOnceFlagsReached then
				if team1Score.Value >= CTFconfig.FlagsRequiredToStop or team2Score.Value >= CTFconfig.FlagsRequiredToStop then
					break
				end

			elseif timeLeft <= 0 then
				break
			end
		end

		if team1Score.Value > team2Score.Value then
			rewardWinner(team1)
		elseif team2Score.Value > team1Score.Value then
			rewardWinner(team2)
		else
			statusValue.Value = "STALEMATE!"
		end

		for i, plr in pairs(game.Players:GetPlayers()) do
			plr.Team = nil
			plr:LoadCharacter()
			plr:WaitForChild("leaderstats"):WaitForChild("Kills").Value = 0
			plr:WaitForChild("leaderstats"):WaitForChild("KillStreak").Value = 0
		end	

		roundSetup.inRound.Value = false
		for i, v in pairs(game.Teams:GetChildren()) do
			if v then
				v:Destroy()
			end
		end
		mapClone:Destroy()
		scoresFolder:Destroy()

		task.wait(CTFconfig.RoundFinishedTime)
	elseif mapClone:WaitForChild("Gamemode").Value == "Deathmatch" then
		
		local mostKills = { -- store current mostkills and the corresponding plr instance
			count = 0,
			plr = nil
		}
		
		local highestValue = Instance.new("ObjectValue", rep)
		highestValue.Name = "HIGHEST KILLS"
		
		for index, plr in pairs(plrs:GetPlayers()) do -- Run through all players
			if plr:FindFirstChild("leaderstats"):FindFirstChild("Kills").Value > mostKills.count then -- Check if their kill count is above mostKills.count
				mostKills.count = plr.leaderstats.Kills.Value -- Set new highest kill count
				mostKills.plr = plr -- set corresponding player
				highestValue.Value = plr
			end
		end
		
		local gameStart = tick()

		while true do
			game:GetService("RunService").Heartbeat:Wait()

			local timeLeft = DMconfig.RoundTime - math.round((tick() - gameStart))
			local mins = math.floor(timeLeft / 60)
			local secs = timeLeft - (mins * 60)
			if string.len(secs) < 2 then
				secs = "0" .. tostring(secs)
			end
			if string.len(mins) < 2 then
				mins = "0" .. tostring(mins)
			end
			statusValue.Value = mins .. ":" .. secs
			if timeLeft <= 0 then
				break
			end
		end
		if highestValue.Value then
			statusValue.Value = highestValue.Value.Name.." WINS!"
		else
			statusValue.Value = "STALEMATE!"
		end

		for i, plr in pairs(game.Players:GetPlayers()) do
			plr.Team = nil
			plr:LoadCharacter()
			plr:WaitForChild("leaderstats"):WaitForChild("Kills").Value = 0
			plr:WaitForChild("leaderstats"):WaitForChild("KillStreak").Value = 0
		end	

		roundSetup.inRound.Value = false
		mapClone:Destroy()
		highestValue:Destroy()

		task.wait(CTFconfig.RoundFinishedTime)
	end
end

i change this part to this:

local function GetHighestKillsPlayer()
			table.sort(plrs:GetPlayers(), function(a,b)
				return a.leaderstats.Kills.Value > b.leaderstats.Kills.Value
			end)
			return plrs:GetPlayers()[1]
		end

		local highestKills = GetHighestKillsPlayer()

works perfectly fine the only problem is the displaying it