Hello, I'm trying to determine if a team of players has won the match by eliminating the other players. Players who die are ignored by the script, they go into the lobby.
Here is what I have, but its not working. Could somebody point out whats wrong or post a working version? Thanks in advance.
local ch = game:GetService("Teams"):GetTeams()
if (#ch ~= 0) then
print("checking for a team win")
local myval = script.PlayersAlive
local total = 0
for i = 1,#ch do
local num = 0
for _, player in pairs(game.Players:GetPlayers()) do
if player.TeamColor == ch[i].TeamColor and player:findFirstChild("Connection") ~= nil then
print(ch[i].Name.." ".. num)
num = num + 1
end
if num > total then total = num end
if myval.Value == total then
print("a team won")
end
end
end
end |