Hey man, sorry you’ve had to wait so long without help. Allow me.
As I understand it, you want to track player deaths yes? We can do this with Humanoid.Died.
Now, I’m not sure how your script is currently structured, so I’m going to make a simple function to demonstrate how you could do this.
The function takes in 2 Team objects, and it will track the player deaths on each team. It will yield the current thread until there is a winning team.
local function GetWinningTeam(Team1: Team, Team2: Team)
print('Starting a new elimation game with teams: ', Team1, 'and', Team2)
local WinningTeam -- The winning team variable. We will assign this to the winning team, when all players on the losing team died.
local Team1Players, Team2Players = Team1:GetPlayers(), Team2:GetPlayers() -- Get the players on both teams.
local RemainingPlayers =
{ -- A dictionary table, to keep track of the number of players alive. Uses the names of the Teams as the keys.
[Team1.Name] = #Team1Players,
[Team2.Name] = #Team2Players,
}
local function TrackPlayer(plr) -- Track a player, to see when they die.
local Character = plr.Character or plr.CharacterAdded:Wait() -- Get the player character. The 'or plr.CharacterAdded:Wait()' is in case the player does not have a character loaded in yet, and the script will wait for them to spawn one, and then use that new one.
local plrTeamName = plr.Team.Name -- Store the player team name, just to make the code cleaner
Character.Humanoid.Died:Connect(function()
-- Player died.
-- Minus the number of players alive on their team.
RemainingPlayers[plrTeamName] -= 1
local TeamRemainingPlayers -- The new number of team members alive, after subtracting the one who just died.
print(plrTeamName, 'only has', TeamRemainingPlayers, 'team members left!')
-- If this player who just died, was the last member on their team, and there is nobody left on the team now, decide the winning team. Also checks to make sure there isn't a winning team already.
if RemainingPlayers[plrTeamName] <= 0 and not WinningTeam then
if plrTeamName == Team1.Name then -- If the player who died was on team 1, then team 2 wins.
WinningTeam = Team2
else -- If the player was on team 2, team 1 wins.
WinningTeam = Team1
end
end
end)
end
-- Track players on both teams
for _, plr in Team1Players do
TrackPlayer(plr)
end
for _, plr in Team2Players do
TrackPlayer(plr)
end
-- Yield the current thread until we have a WinningTeam.
repeat
task.wait(1)
until WinningTeam
return WinningTeam
end
local WinningTeam = GetWinningTeam() -- Pass in your team objects here. For example: GetWinningTeam(BlueTeam, RedTeam). Note that this variable, WinningTeam, will be the Team object that won.
print('And the winning team is', WinningTeam.Name .. '!')
Please do no hesitate to ask any questions! 