0

# Upon Team Death, game ends and one declared victor?

bloxxyz 274
10 years ago

I'm just curious to know how one would be able to do this? I've experimented with the possibility and don't know how and really can't figure it out. Basically, when a round starts, there are two teams, and when one team dies, the other is declared the victor with a Hint at the top of the screen.

I don't want a full script, just some suggestions.

Much thanks.

1
1waffle1 2908
10 years ago

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!"
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.

0
Thanks. bloxxyz 274 — 9y