I need to add wins to people who are on a specific team if it meets specific requirements. If there is more than 0 people on a team at the end of the timer then everyone on that team will get one win. I did not receive any error messages.

local teams = game:GetService("Teams"):GetTeams()
while wait(1) do
for _, team in pairs(teams) do
    local players = team:GetPlayers()
    print("Team " .. team.Name .. " has " .. #players .. " players")
	
 if team.Name == "Hiding" and #players > 0 then
	if game.Workspace.GameActive.Value == true then
	local players = game:GetService("Players")
for i,v in pairs(players:GetPlayers()) do
	if v.TeamColor == BrickColor("Cyan") then
		v.leaderstats.Wins.Value = v.leadersats.Wins.Value + 1
	end
end

end
		end
	end
end

The original script I had worked so I believe the mistake is when I used for i, v in pairs(Players:GetPlayers()) do. This was my original script that did work.

local teams = game:GetService("Teams"):GetTeams()
while wait(1) do
for _, team in pairs(teams) do
    local players = team:GetPlayers()
    print("Team " .. team.Name .. " has " .. #players .. " players")
	
 if team.Name == "Hiding" and #players > 0 then
	if game.Workspace.GameActive.Value == true then
		game.workspace.HidingWinTestA.Value = true
	end
end
end
		end
	end
end

1 comment

0

The second argument in the in pairs loop cannot be the same as a variable.