How to add a win condition to a round based system

What do you want to achieve?
I want to the round to end when there is one person left or all of the enemies are dead (PVP)
What is the issue?
I have no idea how to implement this
What solutions have you tried so far?
I’ve tried keeping all the players in a table and taking them out when they die(which is currently in the code now), and I couldn’t find anything the Dev Forum

The excerpted code from the Round system

local function roundTimer()
	local players = {}
	while wait() do
		game.SoundService.GameIntro.TimePosition = 39
		game.SoundService.GameIntro.Playing = true
		for i =intermissonLength,0,-1 do
			InRound.Value = false
			wait(1)
			status.Value = i
		end
		status.Value = 0
		table.clear(players)
		wait()
		if #game.Players:GetChildren() == 1 then
			game.SoundService.GameIntro.Playing = false
			status.Value = -1
			wait(3)
			spawn(roundTimer)
			break
		end
		RUI:FireAllClients()
		for _,player in pairs(game.Players:GetChildren()) do wait()
			table.insert(players,player.Name)
			local char = player.Character
			char:WaitForChild("Humanoid").Died:Connect(function()
				local index = table.find(players,player.Name)
				table.remove(players,index)
			end)
		end
		for i = 0.15,0.05,-0.0015 do
			game.SoundService.GameIntro.Volume = i
			wait(0.12)
		end
		game.SoundService.GameIntro.Playing = false
		InRound.Value = true
		game.SoundService.GameIntro.TimePosition = 142
		game.SoundService.GameIntro.Playing = true
		game.SoundService.GameIntro.Volume = 0.3
		wait(18.5)
		for i = 0.3,0,0.025 do
			game.SoundService.GameIntro.Volume = i
			wait(0.05)
		end
		game.SoundService.GameIntro.Playing = false
		for i = roundlength,0,-1 do
			InRound.Value = true
            wait(1)			
			status.Value = i
			local vamp = script.Parent.NormalRoles.Vampire.Value
			for _,player in pairs(game.Players:GetChildren()) do
				local char = player.Character
				char:WaitForChild("Humanoid").Died:Connect(function()
					local index = table.find(players,player.Name)
					table.remove(players,index)
				end)
			end
			if i <= 170 then
			local find = table.find(players,vamp.Name,1)
			if table.getn(players) == 1 then
				status.Value = -2
				break
			end
			end
		end
		for i = 1,#game.Workspace.Characters:GetChildren() do
			local charToUndo = game.Workspace.Characters:GetChildren() [i]
			charToUndo.Picked.Value = false
		end
		wait(1)
		InRound.Value = false
		wait(5)
	end
end
1 Like

So you’re making an elimination round?
You could just use the Teams service, and remove players who die, and check if there is only one player left for each team.

Also, you should be using task.wait() rather than wait(), and as for that while loop, if you want it to run every frame, use RunService's Heartbeat and then disconnect that when the win condition is true in the loop.
However, you realistically only want to run this every 3-5 seconds to keep lag to a minimum.

Lastly, use TweenService if you want to fade in/out audio. It’s much simpler than you think.

I’m sorry I didn’t make this more clear so my b.

The teams can work for my first problem but the game is like a murder mystery. I can’t really use teams for that

I see. In this case you should store the murderer’s character in a Murderer variable, and the sheriff’s character in a Sheriff variable. You can check if either becomes nil (when they die), and use that to end or change the game. All other characters can go in an Innocent table. You can connect to the Humanoid's Died event to remove the character from the table. (when the character respawns, the index of that old character will not be deleted, but rather become nil)