i want to get all the kills the whole team has and put it on a Textlabel
the label is not working yet
i want to get all the kills the whole team has and put it on a Textlabel
the label is not working yet
local Amount = 0
for _, Player in pairs(game.Teams.Red:GetPlayers()) do
Amount += Player.leaderstats.Kills.Value
end
TextLabel.Text = Amount
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)
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.
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.
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
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