How to keep a round going if that "one" player is still alive?

Hello, Everyone. This is my first project after 2 years of being inactive in ROBLOX. I’m trying to make a zombie-shooting type game and is still learning to code(Basic).

function System:StartWave() is where I am putting the code. I wanna make it so that if “one” player is still alive in that round and other players are in the lobby, the round will keep going and will teleport the players from the lobby to the round(Once all enemies/zombies are dead, though I already made that script).

I am also having problem with the indicator, if all the players have died and was sent back to the lobby, the round would reset.

I accept any kinds of help and tips, criticizing also. And Thank you.

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")

local SystemFolder = game.Workspace.System
local ZombieFolder = game.Workspace.Zombies
local CountdownFolder = SystemFolder.Countdown

local ZombieModel = ServerStorage.Models.Zombie

local System = {}

System.Time = {

function System:LoadObjects()
	local roundValue ="NumberValue")
	roundValue.Name = "amtRound"
	roundValue.Parent = SystemFolder
	roundValue.Value = 1
	local defZombiesValue ="NumberValue")
	defZombiesValue.Name = "defZombiesValue"
	defZombiesValue.Parent = SystemFolder
	defZombiesValue.Value = 10

	local zombiesValue ="NumberValue")
	zombiesValue.Name = "amtZombies"
	zombiesValue.Parent = SystemFolder
	zombiesValue.Value = 10

	local zombiesMultiplier ="NumberValue")
	zombiesMultiplier.Name = "zombieMultiplier"
	zombiesMultiplier.Parent = SystemFolder
	zombiesMultiplier.Value = 5
	local zombiesThisRound ="NumberValue")
	zombiesThisRound.Name = "zombiesThisRound"
	zombiesThisRound.Parent = SystemFolder
	zombiesThisRound.Value = 0
	local IsRoundCountdown ="BoolValue")
	IsRoundCountdown.Name = "IsRoundCountdown"
	IsRoundCountdown.Parent = SystemFolder
	IsRoundCountdown.Value = 5
	for i, v in pairs(System.Time) do
		local timeType ="IntValue")
		timeType.Name = v
		timeType.Parent = CountdownFolder

function System:StartWave()
	local roundValue = SystemFolder.amtRound
	local zombiesValue = SystemFolder.amtZombies
	local defZombiesValue = SystemFolder.defZombiesValue
	local zombiesMultiplier = SystemFolder.zombieMultiplier
	local zombiesThisRound = SystemFolder.zombiesThisRound
	for _, pl in pairs(Players:GetPlayers()) do
		if pl.InLobby.Value == true then
			local character = pl.Character

			if character then
				local humRootPart = character.HumanoidRootPart
				if humRootPart then
					humRootPart.CFrame = workspace.PlayerSpawn.CFrame
			pl.InLobby = false
			print("Teleporting Player(s).")
			---Once all players died the round must restart
			---Unless "one" player is still alive the round will keep going and teleport all players
			---If that "one" player is dead it will restart
	zombiesThisRound.Value = defZombiesValue.Value + (roundValue.Value - 1) * zombiesMultiplier.Value
	for i = 1, zombiesThisRound.Value do
		local clonedZombie = ZombieModel:Clone()
		clonedZombie.Name = "Zombie" .. i
		clonedZombie.Parent = ZombieFolder

		local humanoidRootPart = clonedZombie:FindFirstChild("HumanoidRootPart")

		if humanoidRootPart then
			humanoidRootPart.CFrame = workspace.ZombieSpawner.CFrame +, 10, 1)
		zombiesValue.Value = #ZombieFolder:GetChildren()


function System:Count()
	local zombiesValue = SystemFolder.amtZombies
	for i in pairs(ZombieFolder:GetChildren()) do
		zombiesValue.Value = #ZombieFolder:GetChildren()
	if #ZombieFolder:GetChildren() == 0 then
		zombiesValue.Value = #ZombieFolder:GetChildren()

function System:Countdown(timeLeft, timer, IsRound)
	local hoursValue = CountdownFolder.Hours
	local minsValue = CountdownFolder.Minutes
	local secondsValue = CountdownFolder.Seconds
	local countdownZombValue = SystemFolder.IsRoundCountdown
	--System:Countdown(10, TimerText)
	for i = timeLeft, 0, -1 do
		timeLeft = i
		countdownZombValue.Value = true
		local hours = math.floor(timeLeft / 3600)
		local minutes = math.floor((timeLeft % 3600) / 60)
		local seconds = math.floor(timeLeft % 60)
		hoursValue.Value = hours
		minsValue.Value = minutes
		secondsValue.Value = seconds
		if IsRound == true and timeLeft == 0 then
			countdownZombValue.Value = false

return System
1 Like

where is the code that ends the round?? unless i am blind

The round goes endlessly. I apologize for not including that.

not sure what is going on here, is this the entire script?

Yes but, here’s a separate script that ends the round if all the enemies/zombies has been killed. Maybe this can also help

	if #Zombies:GetChildren() == 0 then
		roundValue.Value = roundValue.Value +1
		print("Round End")
		SystemModule:Countdown(15, false, true)

but what about checking if the players in the round are still alive or not?

You can check for player characters with iterating through Players:GetPlayers()

local CharacterTable = {}

for _index, value in pairs(Players:GetPlayers()) do
    if value.Character then
        local Character = value.Character
        table.insert(CharacterTable, Character)

if #CharacterTable <= 0 then
    --finish the round

If it is a bit complex to understand:

value is basically the player
_index is basically index of the loop
value.Character is a property of Player instance
#CharacterTable is used to get the lenght of the table/array
table.insert(t: table, v: value) is a function of table library to insert new value to table

1 Like

I have a boolvalue that sets if the player is in the lobby, if it’s false it means the player is in the round or in the map. If it’s true the player is in the lobby

	local indicatorValue ="BoolValue")
	indicatorValue.Name = "InLobby"
	indicatorValue.Parent = pl
	indicatorValue.Value = true
	pl.Character.CharacterAdded:Connect(function(char) -- Not working yet, gives an error
		local hum = char.Humanoid
			indicatorValue.Value = true
			print("Player Died ", indicatorValue.Value) --Test

I’m still confused on using tables, hehe. I’ll to use this

tables are to store multiple variables inside of a variable, think of it as a normal table with lots of food

Tables are basically clusters in the math class.

{} - This is a table and anything inside it seperated with comma will be values.

If you use print for table below you can use:


local table = {
   ["stringKeyForIndex] = "Hello World!"

I really recommend you to learn about tables because you can use them everywhere.
Im also confused about metatables, these are tables’ tables. You don’t have to know it. It is a high grade info.