How can i get the amount of kills a team has?

Screenshot_8

i want to get all the kills the whole team has and put it on a Textlabel

the label is not working yet
Screenshot_9

local Amount = 0

for _, Player in pairs(game.Teams.Red:GetPlayers()) do 
   Amount += Player.leaderstats.Kills.Value
end

TextLabel.Text = Amount
1 Like

where do i put this and in what type of script?

It would be a local script - this is the most basic of scripts. I can write you up a better script in a few minutes.

U want to use Changed/GetPropertyChangedSignal to update the Textlabel.Text everytime a new kills has been added.

If you are gonna use Attributes. Consider using ‘GetAttributeChangedSignal’ (My recommendation)

1 Like

i have time but if this works than its fine right?
and where do i put it?

I’m not on PC at the minute and I am going to write a better script.

Put it under the TextLabel of the GUI.

1 Like
local function updateAmount()
   local Amount = 0
   for _, Player in pairs(game.Teams.Red:GetPlayers()) do 
      Amount += Player.leaderstats.Kills.Value
   end

   TextLabel.Text = Amount
end

for _, Player in pairs(game.Teams.Red:GetPlayers()) do 
   Player.leaderstats.Kills:GetPropertyChangedSignal("Value"):Connect(updateAmount)
end

Thanks! i will try this out right now

I have some trash psuedo code for you, Hopefully u understand the path i am going to make.
Inside the Red Team i have put an attribute named “Amount”.
I have some UI on the client, Every time the Attribute inside the Red team gets incremented it will fire a Remote Event to the server to increment it for the entire server aswell.

local Teams = game:GetService("Teams")
local RedTeam = Teams.Red
local Remote = game:GetService("ReplicatedStorage").RemoteEvent

local textLabel = script.Parent

RedTeam:GetAttributeChangedSignal("Amount"):Connect(function()
	Remote:FireServer(textLabel)
end)

Once on the server i increment it like this

local Teams = game:GetService("Teams")
local RedTeam = Teams.Red
local Remote = game:GetService("ReplicatedStorage").RemoteEvent

Remote.OnServerEvent:Connect(function(Player, textlabel)
	textlabel.Text = RedTeam:GetAttribute("Amount")
end)

And to increment a Attribute i have made a basic script. U don’t have to use it.

local redTeam = game:GetService("Teams").Red

while task.wait(1) do
	redTeam:SetAttribute("Amount", redTeam:GetAttribute("Amount") + 1)
end

This code is written fast and there are prob better ways out there, But i hope u understand a bit what i meant.

it did not work and i did not get any errors to


Wouldn’t it be possible to simply change the total team’s kills in the same script that counts the kills for each individual player?

is this 1 script and where do i put it and what type of script

The first code is inside a local script within the text label.
The second script is a server script in ServerScriptService.
The third script is also in ServerScriptService for test purposes


what is this?

I think u did something wrong since i don’t get that error
BobbieTrooper’s Place Number: 154 - Roblox Studio (gyazo.com)

Also is the Attribute called “Amount” A number?

ohh wait a few seconds i think i fixed it brb

or not is it the same for you my kills go up every seconds or so