How to give all players in a team a win

I have been trying to make a win value which doesn’t be in the leaderboard on the GUI which shows all the players, I have tried to make it give a win to the winning team but it ends up giving everyone the win

function GiveWins(team, amount)
	for _, player in pairs(team:GetPlayers()) do
		print(player.Parent.Parent)
		if player.Team == team then
			player.Parent.Parent.ReplicatedStorage.leaderstats.Wins.Value = player.Parent.Parent.ReplicatedStorage.leaderstats.Wins.Value + 1
		end
	end
end

Any help is appreciated

Note: Script is in a Server script

1 Like
local function GiveTeamWins(TeamName,Amount)
  for _,player in pairs(game.Players:GetChildren()) do
    if player.Team.Name == TeamName then
      player.leaderstasts.Wins.Value += Amount
    end
  end
end
2 Likes
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")

local function GiveTeamStats(Team:Team,Amount:number)
  for _,player in pairs(Players:GetPlayers()) do
    if player.Team == Teams:FindFirstChild(Team) then
      player.leaderstasts.Wins.Value += Amount
    end
  end
end
1 Like
function GiveWins(team, amount)
	local teams = {["a"]=Color3.FromRGB(255,255,255),["b"]=Color3.FromRGB(0,0,0)}
	for _, player in pairs(team:GetPlayers()) do
		if player.TeamColor == teams[team] then
			player.leaderstats.Wins.Value += amount
			print(player.Name .. " now have " .. player.leaderstats.Wins.Value .. " Wins.")
		end
	end
end
1 Like

Your script has a error there.

player.TeamColor == teams[team] -- Color == Instance?
player.TeamColor == teams[team].Color

I didn’t use the leaderstats for player i put the leaderstats in replicatedstorage

1 Like

then just change the directory.

1 Like

Also one thing about your script

function GiveWins(team, amount)
	for _, player in pairs(team:GetPlayers()) do
		print(player.Parent.Parent)
		if player.Team == team then
			player.Parent.Parent.ReplicatedStorage.leaderstats.Wins.Value = player.Parent.Parent.ReplicatedStorage.leaderstats.Wins.Value + 1 -- Replicated storage is in the game correct? so why use player.Parent.Parent? just do game.ReplicatedStorage.
		end
	end
end
function GiveWins(team, amount)
	for _, player in pairs(team:GetPlayers()) do
		print(player.Parent.Parent)
		if player.Team == team then
			game.ReplicatedStorage.leaderstats.Wins.Value += 1
		end
	end
end

Same issue happening at the moment

and may I ask what the issue is?

It is giving every player a win in-game if they have lost

prob cuz how you parented wins… in replicated storage… you must parent it to the player in order for it to work.

1 Like

Yea I think the wins are just saved to the server and its using the same value of wins for everyone

yes exactly. because the script logic is accurate.

1 Like

Now im just going to figure out how to make hidden stats thank you for the help

You create a stat for each player, as suggested and increment that stat’s value by 1 (for each player on the winning team).