local t1 = 0
local t2 = 0
local t3 = 0
local t4 = 0
for _, i in pairs(game.Players:GetChildren()) do
if i.Team.Name == "Team 1" then
t1+=0
end
if i.Team.Name == "Team 2" then
t2+=0
end
if i.Team.Name == "Team 3" then
t3+=0
end
if i.Team.Name == "Team 4" then
t4+=0
end
end
if t1 > 0 and t2 == 0 and t3 == 0 and t4 == 0 then
--team 1 win stuff
end
if t2 > 0 and t1 == 0 and t3 == 0 and t4 == 0 then
--team 2 win stuff
end
if t3 > 0 and t2 == 0 and t1 == 0 and t4 == 0 then
--team 3 win stuff
end
if t4 > 0 and t2 == 0 and t3 == 0 and t1 == 0 then
--team 4 win stuff
end
whenever a player leaves or player.Team changes, for loop through team objects, excluding spectators, have some sort of active teams table where if #players>=1 then table.insert into activeteams table
at the end of iteration if #activeteams==1 then that team wins, if #activeteams==0 tie, else, continue game
sample code
function CheckWinCondition()
local ActiveTeams={}
--for loop through all teams except specators
for index, team in pairs (TeamsFolder) do
if #team:GetPlayers()>=1 then
table.insert(ActiveTeams, team)
end
end
if #ActiveTeams==0 or #ActiveTeams==1 then
return true
else
return false
end
end
--after initializing game loop and teams are set up
loop through all teams except spectators
for index, player in pairs (team1:GetPlayers())
player:GetPropertyChangedSignal("Team"):Once(function()
--we can assume someteam->Spectator so checkwin condition
if CheckWinCondition()==true then
--stop the game
end
end)
end