Team leaderstat added together issue

Hello, everyone, I am having an issue with my script. Whenever, the script tries to add the team player’s leaderstat, it only detects it for one player. For example, if Player 1 has 10 kills and Player 2 has 5 kills, the script shows only 10 kills instead of 15. (Picture of proof)

Script:

local redteam = game:GetService("Teams").Red
local totalAmmount = 0
local Players = game:GetService("Players")
local kill = game:GetService("ReplicatedStorage").RemoteEvents.Change
local var1
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		for i,v in pairs(redteam:GetPlayers()) do
			var1 = v
		end
		var1.leaderstats:WaitForChild("Kills").Changed:Connect(function()
			for i,v in pairs(redteam:GetPlayers()) do
				local killstat = v.leaderstats.Kills
				totalAmmount = killstat.Value
				kill:FireAllClients(totalAmmount)
			end
		end)
	end)
end)

Local Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage.RemoteEvents:WaitForChild("Change")

local function updategui(path)
	local Info = TweenInfo.new(0.15)
	local Tween = game:GetService("TweenService"):Create(script.Parent,Info,{Size = UDim2.new(path/50, 0, 1, 0)})
	Tween:Play()
	script.Parent.Parent.RedLabel.Text = path
end
remoteEvent.OnClientEvent:Connect(updategui)

Picture:

Edit: Also, the other player also shows 11, not 3.


local redteam = game:GetService("Teams").Red
local totalAmount = 0
local Players = game:GetService("Players")
local kill = game:GetService("ReplicatedStorage").RemoteEvents.Change
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	plr:WaitForChild("leaderstats"):WaitForChild("Kills").Changed:Connect(function()
		totalAmount += plr.leaderstats.Kills.Value
		kill:FireAllClients(totalAmount)
	end)
end)

Give this a try and let me know if it works @SupremeSuperSoCool

uhhh, now it just multiply itself by a random number.

Sorry, try this instead:

local redteam = game:GetService("Teams").Red
local totalAmount = 0
local Players = game:GetService("Players")
local kill = game:GetService("ReplicatedStorage").RemoteEvents.Change
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	plr:WaitForChild("leaderstats"):WaitForChild("Kills").Changed:Connect(function()
		totalAmount += 1
		kill:FireAllClients(totalAmount)
	end)
end)

it worked!!! thank you for the help (i really suck at scripting :slight_smile: )

1 Like

Sure, mark the post I just sent as the solution so people don’t think that you still need help.

1 Like

btw for anyone trying to use this script with two teams, here is a script for that

Script:

local redteam = game:GetService("Teams").Red
local blueteam = game:GetService("Teams").Blue
local redteamscore = 0
local blueteamscore = 0
local Players = game:GetService("Players")
local kill = game:GetService("ReplicatedStorage").RemoteEvents.Change
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	player:WaitForChild("leaderstats"):WaitForChild("Kills").Changed:Connect(function()
		if player.Team == redteam then
			redteamscore += 1
			kill:FireAllClients(redteamscore, "Red")
		end
		if player.Team == blueteam then
			blueteamscore += 1
			kill:FireAllClients(blueteamscore, "Blue")
		end
	end)
end)

Local Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage.RemoteEvents:WaitForChild("Change")

local function updategui(path, whichteam)
	if whichteam == "Red" then
		local Info = TweenInfo.new(0.15)
		local Tween = game:GetService("TweenService"):Create(script.Parent.Red.Fill,Info,{Size = UDim2.new(path/50, 0, 1, 0)})
		Tween:Play()
		script.Parent.Red.RedLabel.Text = path
	end
	if whichteam == "Blue" then
		local Info = TweenInfo.new(0.15)
		local Tween = game:GetService("TweenService"):Create(script.Parent.Blue.Fill,Info,{Size = UDim2.new(path/50, 0, 1, 0)})
		Tween:Play()
		script.Parent.Blue.BlueLabel.Text = path
	end
end
remoteEvent.OnClientEvent:Connect(updategui)