How would I make the round end when if all players are dead

I made a round system I will provide all the scripts at the end but I made a round system and I want it to end the round if all players are dead because I dont want them to wait until the round is over if they are all dead I tried and tried but none work I also made a intermission which is in the round system script. I hope someone can help.

Round system and intermission script:

( I have a remote event name “TimeEvent” in ReplicatedStorage)

local lobbyLocation = game.Workspace.Lobby.Position + Vector3.new(0,3,0)

local gameLocation = game.Workspace.Main.Position + Vector3.new(0,3,0)

local ReplicatedStorage = game:GetService(‘ReplicatedStorage’)

local timeEvent = ReplicatedStorage:WaitForChild(‘TimeEvent’)

local function playGame()

local timeAmount = 160

local timerText = 'Remaining Time: ’

local player = game.Players.LocalPlayer

while timeAmount > 0 do

  timeEvent:FireAllClients(timeAmount, timerText)

  wait(1)

  timeAmount -= 1

end

end

local function playIntermission()

local intermission = 30

local timerText = 'Intermission: ’

while intermission > 0 do

  timeEvent:FireAllClients(intermission, timerText)

  wait(1)

  intermission -= 1

end

end

local function resetPlayers()

for _, plr in pairs(game.Players:GetChildren()) do

  plr.Character.HumanoidRootPart.CFrame = CFrame.new(lobbyLocation)

end

end

local function teleportPlayers()

for _, plr in pairs(game.Players:GetChildren()) do

  plr.Character.HumanoidRootPart.CFrame = CFrame.new(gameLocation)

end

end

while true do

resetPlayers()

playIntermission()

teleportPlayers()

playGame()

Maybe you can have a variable and when a player dies you add 1 to that variable. If the variable is equal to how much players was alive at the start then everyone died.

You could do a player table and remove a player when they die. Check if the table is clear and then proceed with your code

local playersInRound = {}

if #playersInRound == 0 then
    print("all players died")
end
1 Like
old thingy

local player = game.Players.LocalPlayer
while timeAmount > 0 do
timeEvent:FireAllClients(timeAmount, timerText)

how are you firing all clients from the clientside its not possible

actually nvm I remember that wrong.

but on the end for the player dying,

then add a .Died and a .PlayerRemoving for the checking when they die

1 Like

Yes it is im just firing the client pretty much its not much different

wait when do I add .Died and .PlayerRemoving?

Maybe include it within this function?

local function playGame()
    local player = game:GetService('Players').LocalPlayer
    local timeAmount = 160
    local timerText = "Remaining Time: "

    player.Character.Humanoid.Died:Connect(function()
        table.remove(playersInRound,player)
    end)

    game.Players.PlayerRemoving:Connect(function(plr)
        if table.find(playersInRound,plr) then
            table.remove(playersInRound,plr)
        end
    end)    
end

Try testing code to see if this works

Ok I will thank you I hope it works thank you again

Hmmm it worked until it got to the round where it basically broke also there is something wrong with died in player.Character.Humanoid.“Died”.

so this will be my attempt at it. I did this all in notepad so

I would change it to the server to begin with,
you don’t really want 1 player to have complete control over the game,
they could make it send bad things with the fireallcients instead change it to the server side

Script
local lobbyLocation = game.Workspace.Lobby.Position + Vector3.new(0,3,0)
local gameLocation = game.Workspace.Main.Position + Vector3.new(0,3,0)
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local timeEvent = ReplicatedStorage:WaitForChild('TimeEvent')

playersInRound = {} -- table with players in the round

local function playGame()

	local timeAmount = 160
	local timerText = 'Remaining Time: '

	while timeAmount > 0 do 
        if #playersInRound <=1 then-- ends round, this is done with spaces so youll have to  reformat this
            timeAmount -= 1
            continue 
        end
		for _, player in pairs(playersInRound) do
			if not player then continue end -- just in case they leave at the perfect time to mess this up
			timeEvent:FireClient(player,timeAmount, timerText)
		end
		wait(1)
		timeAmount -= 1
	end

end

local function playIntermission()
	local intermission = 30
	local timerText = 'Intermission: '
    playersInRound = game:GetService("Players"):GetPlayers()

	while intermission > 0 do
		for _, player in pairs(playersInRound) do
			if not player then continue end 
			timeEvent:FireClient(player,timeAmount, timerText)
		end
  	wait(1)
	intermission -= 1
	end
end

local function resetPlayers()
	for _, plr in pairs(playersInRound) do
		if not plr then continue end
		plr.Character.HumanoidRootPart.CFrame = CFrame.new(lobbyLocation)
	end
end

local function teleportPlayers()
	for _, plr in pairs(playersInRound) do
		if not plr then continue end
		plr.Character.HumanoidRootPart.CFrame = CFrame.new(gameLocation)
	end
end

-- player died
game.Players.PlayerAdded:Connect(function(player)
	player.Character:WaitForChild("Humanoid").Died:Connect(function()
		if table.find(playersInRound,player) then
			table.remove(table.find(playersInRound,player))
		end
	end)
end)

--playerRemoving
game.Players.PlayerRemoving:Connect(function(player)
	if table.find(playersInRound,player) then
		table.remove(table.find(playersInRound,player))
	end
end)

-- I guess the game loop part
while true do

	--reset players (send to lobby)
	resetPlayers()
	--play intermission, also resets the player list
	playIntermission()
	--teleport players
	teleportPlayers()
	--start game
	playGame()

end

put this in a normal script and put the script in serverscriptservice, do keep the scripts that read the client event
this is just the script that runs the game, not deals with gui stuff

please tell me if this works. I haven’t tested it

edit: i forgot to add a way to end the round if everyone died, thats been fixed

Well how will the player die, if they die with a sword use a event that adds to how many players are dead when hit, if they are supposed to fall then add a part in the bottom that when touched adds a dead player to the value/table

Ok I will try thank you I hope this works

Thank you its good have a good day