Could someone help me with this please? (round system between teams)

Hello, I hope you are well, so I need to make a system of rounds between teams since my game is that there are several game modes 1 vs 1, 2 vs 2, 3 vs 3 and 4 vs 4 but the problem is that I need the server to know when all the players of your team have died for another round to start here is the script but I don’t know how to do it I’m confused and I don’t know what to do:slightly_smiling_face:

local remote = game.ReplicatedStorage.RemoteEvent
local espera = game.Workspace.wait
local espera2 = game.Workspace.wait2
local esperar = game.ReplicatedStorage.esperar
local sonido = espera.sonido
local valor2 = game.Teams.gladiador.valordeequipo
local valor1 = game.Teams.guerrero.valordeequipo
local puntos = game.Teams.gladiador.puntos
local puntos2 = game.Teams.guerrero.puntos
local sonido2 = espera2.sonido
local tabla = {}
game.Players.PlayerAdded:Connect(function(plr)
	for i , team in pairs(game.Teams:GetChildren()) do
		table.insert(tabla,team.Name)
		
	end
	end)

I don’t even know how to get the children at least tell me how to do it please help me

I don’t need any script just tips on how to do it

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! :wink:

hey thanks I’ll see and analyze tomorrow I have to sleep because I live in Colombia and it’s already 12 thank you very much

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.