How do i find the entire deaths of each team

I wanna make every team have a value of all the players in the exact teams deaths and I mean all the players

the issue is even the script you will see when your scroll down doesn’t not update one of my friends told me you need render stepped for the script but as I said im trying to add the a stat in each team getting every players deaths so that I can add for my playerlist I have been searching how to do this but I couldn’t find people doing a script for every teams deaths added in the teams folder

  1. I have tried to do team:getplayers but it only got 1 player and its a local script I did it a server script but still nothing

local count = 0
for i,v in pairs(game:GetService(“Teams”):GetChildren()) do
if v:IsA(“Team”) then
for i,v1 in pairs(v:GetPlayers()) do
count = count + v1:FindFirstChild(“leaderstats”).Deaths.value
v:FindFirstChild(“Death”).value = count
end
end
end
end
end
end
end
end

To properly update the total deaths for each team, you need to use a server-side script and connect to the PlayerAdded event to listen for new players joining the game. Additionally, you’ll need to set up a loop to update the total deaths for each team. Here’s a script that should work for your needs:

local Teams = game:GetService("Teams")
local Players = game:GetService("Players")

local function updateTeamDeaths(team)
	local totalDeaths = 0
	for _, player in ipairs(team:GetPlayers()) do
		local leaderstats = player:FindFirstChild("leaderstats")
		if leaderstats then
			local deaths = leaderstats:FindFirstChild("Deaths")
			if deaths then
				totalDeaths = totalDeaths + deaths.Value
			end
		end
	end
	local teamDeaths = team:FindFirstChild("Deaths")
	if not teamDeaths then
		teamDeaths = Instance.new("IntValue")
		teamDeaths.Name = "Deaths"
		teamDeaths.Parent = team
	end
	teamDeaths.Value = totalDeaths
end

local function onPlayerAdded(player)
	player.CharacterAdded:Connect(function(character)
		wait(2) -- Wait for leaderstats to be created
		local team = player.Team
		if team then
			updateTeamDeaths(team)
		end
	end)
end

Players.PlayerAdded:Connect(onPlayerAdded)

for _, player in ipairs(Players:GetPlayers()) do
	onPlayerAdded(player)
end

while true do
	wait(1)
	for _, team in ipairs(Teams:GetChildren()) do
		if team:IsA("Team") then
			updateTeamDeaths(team)
		end
	end
end

This script does the following:

  1. Listens for new players joining the game and connects to their CharacterAdded event.
  2. When a character is added, it waits for a short time to ensure the leaderstats object is created, then updates the team’s total deaths.
  3. A loop at the end of the script updates the total deaths for each team every second to ensure the values stay up-to-date.

This script should be placed in a Script object within ServerScriptService.

wow thank you you really helped me with my game

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