How would I end the round when all the players die?

I know you’re supposed to have scripts and all, but I’ve been trying for 6 hours today. I’m tired of people trying to make alterations to my scripts. I just need ideas, because I am completely out.

A little backround information though, the current round system for me is this:

-intermission timer
-players organized into teams and teleported to game area along with game timer countdown
-when time runs out or one team wins, the game timer ends
-players teleported back to lobby and placed into the neutral team, which is an actual team and not the default neutral team.

Any ideas would be super helpful, as this is (at least to my knowledge) the last thing I need to accomplish before I officially release my game. If you help me I’ll give you free hats, haha.

2 Likes

When a player dies, are they removed from the team? If this is the case, then you can just listen to Team.PlayerRemoved and check if the number of players on the team is 0. This will not only detect when everyone dies, but if everyone leaves and all such edge cases.

Psuedocode:

Team.PlayerRemoved:Connect(function(player)
     if #Team:GetPlayers() == 0 then
          print(Team.Name .. " has no more players!"
     end
end)
1 Like

I would just say make a table. At the point in the script when you put everyone in the game you add all the players into the table the table has two entries something like this.

local PlayersAlive = {
["Team1"] = {},
["Team2"] = {}
}

When a player dies, in your (I’m assuming you have this in your script) Humanoid.Died function, you would remove them from the table. You would do the same for player removing. Finally in your game timer countdown part in your script every second you’d have an if statement that checks if #PlayersAlive[“Team1”] or #PlayersAlive[“Team2”] == 0 then you can break the loop or do whatever you’d need to do to end it.

Also just a question cause I’ve been saying this same script a lot… I looked through your profile. Is it from some video?

1 Like

For some reason it wouldn’t print. And yes, when the player dies they are removed from the team.

Your script almost works, the only problem is that the loop breaks even when there is a player in the runners team.

I’m not exactly sure what your question means, but I would be happy to answer once I know.

1 Like

does it break when there’s one runner, or when the first runner dies? Also ik you probably got this but in my original comment i said #PlayersAlive[“Team1”] or #PlayersAlive[“Team2”] == 0. Make sure you do
#PlayersAlive[“Team1”] == 0 or #PlayersAlive[“Team2”] == 0.

My question is, is the script your using from a video?

It breaks when there is one runner.

The script was from a video, this one in fact.

Can you show the script? I know you said you didn’t want t, but you sound like your really close to finishing.

Check your other thread, I posted a solution to a potential problem.

Here is the entire script. I’m sorry it’s really long, but it should be pretty organized. Your code should be in the RoundTimer function.

local roundLength = 60
local intermissionLength = 10
local victoryLength = 15
local deathLength = 5
local InRound = game.ReplicatedStorage.InRound
local lobbyspawn = game.Workspace.LobbyAreaSpawn
local gamespawn = game.Workspace.GameAreaSpawn
local deathspawn = game.Workspace.deathspawn
local status = game.ReplicatedStorage.Status
local won = game.ReplicatedStorage.Won
local died = game.ReplicatedStorage.Died

local runnerTeam = game.Teams.Runners

local music = game.Workspace.music
local music1 = game.Workspace.music_duplex
local music2 = game.Workspace.music_duplexwon
local trombone = game.Workspace.trombone

local runnersTable = game.Teams.Runners:GetPlayers()

local title = game.StarterGui.Menu.TitleScreen

game.Players.PlayerAdded:Connect(function(player)
	local Neutral = game.Teams.Neutral
    player.Team = Neutral
end)

InRound.Changed:Connect(function()
	if InRound.Value == true then	
		local death = game.Teams.Death -- this sets the teams
		local runnersTeam = game.Teams.Runners
		local plrs = game.Players
		local runners = {}
			repeat wait(1) until #plrs:GetPlayers() > 0
		local chosen = plrs:GetChildren()[math.random(1, #plrs:GetChildren())]
		for i, plr in pairs(plrs:GetChildren()) do 
			if plr ~= chosen then
				table.insert(runners, plr)
				plr.Team = runnersTeam
			else
				plr.Team = death
			end
		print("teams have been chosen")
		end	
	
		for _, player in pairs(game.Players:GetChildren()) do -- this teleports the players
			local char = player.Character
			if player.Team == runnersTeam then
				char.HumanoidRootPart.CFrame = gamespawn.CFrame
			else
				char.HumanoidRootPart.CFrame = deathspawn.CFrame
			end
		end
		print("players have teleported to the game area")
	else --if the round isn't going, this places everyone in the neutral team and teleports them to the lobby
		local plrs = game.Players
		local Neutral = game.Teams.Neutral
		for i, plr in pairs(plrs:GetChildren()) do
			plr.Team = Neutral
		end
		print("all players have been placed in neutral")
		for _, player in pairs(game.Players:GetChildren()) do
			local char = player.Character
			char.HumanoidRootPart.CFrame = lobbyspawn.CFrame
		end		
		print("players have teleported to the lobby")
	end
end)

local function RoundTimer() --this is the timer for the rounds. It changes the text in a GUI as well
	while wait() do
		if won.Value == false then
			music:Play()
			music1:Stop()
			for i = intermissionLength, 0, -1 do
				InRound.Value = false
				wait(1)
				status.Value = "Intermission: ".. i .." seconds left!"
			end
			music:Stop()
			music1:Play()
			for i = roundLength, 0, -1 do			
				InRound.Value = true	

				local PlayersAlive = {
				["Runners"] = {},
				["Death"] = {}
				}
	
				if #PlayersAlive["Runners"]==0 then
					music1:Play()
					status.Value = "Game will start momentarily"
					wait(5)
					if	#PlayersAlive["Runners"]==0 then
						music1:Stop()
						for _, player in pairs(game.Players:GetChildren()) do
							local char = player.Character
							char.HumanoidRootPart.CFrame = lobbyspawn.CFrame
						end			
					
						for i = deathLength, 0, -1 do
							wait(1)
							status.Value = "Death has destroyed the runners!"
						end	
						InRound.Value = false
						won.Value = false
						break
					end
				end
			
				if won.Value == true then
					break
				end
				wait(1)
				status.Value = "Game: ".. i .." seconds left!"
			end	
		else
			music:Stop()
			music1:Stop()
			music2:Play()
			for i = victoryLength, 0, -1 do
				wait(1)
				status.Value = "The runners have beaten death!"
			end

			for _, player in pairs(game.Players:GetChildren()) do
				local char = player.Character
				char.HumanoidRootPart.CFrame = lobbyspawn.CFrame
			end		
			won.Value = false
		end
	end
end

spawn(RoundTimer)
1 Like

This has been solved by an external source, thank you all for your help.