How can I make this script reset when all players die?

Hello! I have this minigame script. The thing is when all the players die on a level, the countdown still keeps going. I would like help modifying this to make it so when all players on a level die, it goes to intermission (restarting the script). Here is the script:

local s = script.Stat
local vals = game.ReplicatedStorage.vals
t = 0
while true do
	t = 15
	repeat
		t = t-1
		s.Value = "Intermission.. "..t
		wait(1)
	until t == 0
	s.Value = "Game starting!"
	wait(2)
	local mapselect = game.ReplicatedStorage.Games:GetChildren()
	local choose = math.random(1,#mapselect)
	curnum = 0
	for i =1,#mapselect do
		curnum = curnum +1
		if curnum == choose then
			mapselect[i]:Clone().Parent = workspace
			curmap = mapselect[i].Name
			s.Value = "We'll be playing "..mapselect[i].Name
		end
	end
	wait(3)
	local plrs = game.Players:GetChildren()
	for i = 1,#plrs do
		local num = math.random(1,32)
		plrs[i].Character.Head.CFrame = CFrame.new(workspace.Teleports["Part"..num].Position)
		plrs[i].Character.Parent = workspace.Ingame
	end
	t=100
	repeat
		t = t-1
		s.Value = t.." seconds left"
		wait(1)
	until t ==0 or vals.Winner.Value ~= ""
	if vals.Winner.Value ~= "" then
		s.Value = vals.Winner.Value.. " has won!"
		game.Players[vals.Winner.Value].leaderstats.Points.Value =game.Players[vals.Winner.Value].leaderstats.Points.Value +50
		game.Players[vals.Winner.Value].leaderstats.Wins.Value = 	game.Players[vals.Winner.Value].leaderstats.Wins.Value +1
		vals.Winner.Value = ""
	else
		s.Value = "No one has won!"
	end
	wait(3)
	local ingame = workspace.Ingame:GetChildren()
	for i =1,#ingame do
		local plr = game.Players:GetPlayerFromCharacter(ingame[i])
		plr:LoadCharacter()
		
	end
	workspace[curmap]:Destroy()
end

EDIT: If I was not clear enough, please let me know.

Have players in a table, remove them once they die. Every time a player dies the table gets checked, if theres nothing in the table then game finishes.
Or you could make a value that is #alive then subtract from that value every time a player dies and check if the value is 0 and if it is make game end

Well, there are 2 ways of doing this from what I see anyway.

The 1st way you could do this is getting all the players within the game and having an if statement check the number of players there are within the loop you have every time the loop ticks.

2nd-way for example in your loop, you would have a timer to keep track of how long the game has left, within that time you can have a function that checks the number of players left every time that timer ticks, and when that timer ticks and it detects the number of players is zero or whatever your preference is reset the script and start from intermission again.

Hey! Thanks, but any idea of how I would go about making that?

1 Like