How do I stop a GUI display of leaderboard stats from lowering the value when a player leaves?

--Script Under my GUI

local textlabel = script.Parent

local function TeamKills(teamName)
	local allKills = 0
	for _, player in ipairs(game.Players:GetPlayers()) do
		if player.Team and player.Team.Name == teamName and player.leaderstats then
			allKills = allKills + player.leaderstats.Kills.Value
		end
	end
	return allKills
end


local Team = "Alpha"

while true do
	textlabel.Text = TeamKills(Team)
	wait(.1)  
end

As you can see, this is to display the stats of the leaderboard on a Textlabel

Imagine this

Team “Alpha” needs 20 kills to win, and is at 19 kills.
Suddenly, a player on team alpha with 4 kills disconnects and now the team has 15 kills, and loses the game because of this.

What I want to happen is that even when said player leaves, the value remains as is, and can just keep going

because of this, Team “Alpha” can still win with just one more kill because they didn’t lose 4 points when one of their players left.

Can someone please explain to me to achieve this?

1 Like

You could just use a variable for each time to track total kills team-wide. throughout that round, then reset it when the round is over so. That’s like the simplest way to execute it in my head.

Yea something like each time you give a player +1 kills, you could also do something like:

-- assuming player.Team isnt nil and Kills isnt nil
player.Team:SetAttribute("Kills", player.Team:GetAttribute("Kills")+1)

Then this value could be changed in the leaderboard :smiley: