✓ Accepted answer
It seemed neat so I had to write the whole code.
local teams={}
for _,v in pairs(game.Players:GetPlayers())do
local team=tostring(v.TeamColor)
teams[team]=teams[team]or{0}
local t=teams[team]
t[1]=t[1]+1
while not v.Character do wait()end
local index=#t+1
t[index]=v.Character.Changed:connect(function()
t[1]=t[1]-1
if t[1]==0 then
for i=2,#t do
t[i]:disconnect()
end
local winner=""
local winners=0
for name,v in pairs(teams)do
if v[1]>0 then
winner=name
winners=winners+1
end
end
if winners==1 then
local hint=Instance.new("Hint",workspace)
hint.Text=winner.." is the winning team!"
game:service("Debris"):AddItem(hint)
for _,x in pairs(teams)do
for i=2,#x do
x[i]:disconnect()
end
x[1]=0
end
end
else
t[index]:disconnect()
end
end)
end
This creates a list of each team and adds a connection to each player's character to their listed team. When their character changes (dies/leaves), the player count decreases on that team. If the player count reaches 0 then it checks each other team, and if only one team has a player count greater than 0, that team is declared the winner. The hint is collected by Debris within 10 seconds.
1 comment
Thanks.