Can I have some help with my round script?

  1. What do you want to achieve?
    I want to get my script working again, but I can’t seem to fix it.

  2. What is the issue?
    This Is a battle royale script and I just made it to the part where I have to end the round, but it is not displaying the winner when a player has died and it won’t go to the cleanup part of the script

  3. What solutions have you tried so far?
    I have tried to debug the code trying different methods but it just won’t work…

here is the script

-- define variables
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local StarterGui = game:GetService("StarterGui")
local Status = ReplicatedStorage:WaitForChild("StatusValue")
local MapsFolder = ServerStorage:WaitForChild("Maps")

-- first we need to create the loop
while true do
	wait(5) -- wait so then the script dosen't crash 
	
	Status.Value = "Waiting for enough players..."
	
	repeat wait() until game.Players.NumPlayers >= 2
	
	Status.Value = "Intermission"
	
	
	-- Add all players in table in put them in it
	local Plrs = {}
	
	for i,player in pairs(game.Players:GetChildren()) do
		if player then
			table.insert(Plrs,player)
		end
	end
	
	-- choose a random map and clone it and put it in the workspace. 
	local AvaibleMaps = MapsFolder:GetChildren()
	
	local ChosenMap = AvaibleMaps[math.random(1,#AvaibleMaps)]
	
	Status.Value = ChosenMap.Name.."chosen"
	
	ChosenMapClone = ChosenMap:Clone()
	ChosenMapClone.Parent = game.Workspace
	
	wait(2)
	
	-- teleport the players to the map
	
	-- first make a table with all of the avaible spawn points. 
	local SpawnPositions = ChosenMap:FindFirstChild("SpawnPoints")
	
	local SpawnPoints = SpawnPositions:GetChildren()
	
	
	-- start spawning the players
	for i,player in pairs(Plrs) do
		if player then
			
			character = player.Character
			
			if character then
				character:PivotTo(SpawnPoints[1].CFrame)
				table.remove(SpawnPoints,1)
				
				-- Give them a sword
				local Sword = ServerStorage.Sword:Clone()
				Sword.Parent = player.Backpack
				
				-- Give them their game tag
				local Gametag = Instance.new("BoolValue")
				Gametag.Name = "GameTag"
				Gametag.Parent = player
				
			
		else
			-- there is no avaible character so remove them.
			if not character then
				table.remove(Plrs,i)
				print("character no found")
			end
		end
	end
	end
	
	
	-- start the round and add a timer to check and see if someone dies 
	for i = 60,0,-1 do
		wait(1)
		Status.Value = "There are"..i.."seconds remaining."
		
		for i,player in pairs(Plrs) do
			if player:FindFirstChild("GameTag") and player.Character.Humanoid.Health ~= 0 then
				print("A player is still fighting")
			else
				print("a player died")
				table.remove(Plrs,i)
				player.GameTag:Destroy()
				
			end
			
			if i == 0 then -- this part and below is part is is not working.
				Status.Value = "Time ran out, nobody won!"
				print("time ran out")
			elseif #Plrs == 1 then
				print("reseting round!")
				Status.Value = "the winner is"..Plrs[1].Name
				table.remove(Plrs,1)
				ChosenMap:Destroy()
				break
			end
		end
		
	end
	
	-- cleanup 
	print("cleaning up!")
	
	
end

thank you for reading!

the if i == 0 is referred to i from this loop rather than the one above it

Change the above to and it should work

for _,player in pairs(Plrs) do
			if player:FindFirstChild("GameTag") and player.Character.Humanoid.Health ~= 0 then
				print("A player is still fighting")
			else
				print("a player died")
				table.remove(Plrs,_)
				player.GameTag:Destroy()
				
			end

Ok, it seems it works now. The last problem is that it needs to print “cleanup” in the output so then it will break out of the loop and reset the round.

What’s the final string that prints before it breaks?

Try the following, I ended this loop before checking if i == 0

-- define variables
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local StarterGui = game:GetService("StarterGui")
local Status = ReplicatedStorage:WaitForChild("StatusValue")
local MapsFolder = ServerStorage:WaitForChild("Maps")

-- first we need to create the loop
while true do
	wait(5) -- wait so then the script dosen't crash 

	Status.Value = "Waiting for enough players..."

	repeat wait() until game.Players.NumPlayers >= 2

	Status.Value = "Intermission"


	-- Add all players in table in put them in it
	local Plrs = {}

	for i,player in pairs(game.Players:GetChildren()) do
		if player then
			table.insert(Plrs,player)
		end
	end

	-- choose a random map and clone it and put it in the workspace. 
	local AvaibleMaps = MapsFolder:GetChildren()

	local ChosenMap = AvaibleMaps[math.random(1,#AvaibleMaps)]

	Status.Value = ChosenMap.Name.."chosen"

	ChosenMapClone = ChosenMap:Clone()
	ChosenMapClone.Parent = game.Workspace

	wait(2)

	-- teleport the players to the map

	-- first make a table with all of the avaible spawn points. 
	local SpawnPositions = ChosenMap:FindFirstChild("SpawnPoints")

	local SpawnPoints = SpawnPositions:GetChildren()


	-- start spawning the players
	for i,player in pairs(Plrs) do
		if player then

			character = player.Character

			if character then
				character:PivotTo(SpawnPoints[1].CFrame)
				table.remove(SpawnPoints,1)

				-- Give them a sword
				local Sword = ServerStorage.Sword:Clone()
				Sword.Parent = player.Backpack

				-- Give them their game tag
				local Gametag = Instance.new("BoolValue")
				Gametag.Name = "GameTag"
				Gametag.Parent = player


			else
				-- there is no avaible character so remove them.
				if not character then
					table.remove(Plrs,i)
					print("character no found")
				end
			end
		end
	end

	-- start the round and add a timer to check and see if someone dies 
	for i = 60,0,-1 do
		wait(1)
		Status.Value = "There are"..i.."seconds remaining."

		for i,player in pairs(Plrs) do
			if player:FindFirstChild("GameTag") and player.Character.Humanoid.Health ~= 0 then
				print("A player is still fighting")
			else
				print("a player died")
				table.remove(Plrs,i)
				player.GameTag:Destroy()
			end
		end
		
		if i == 0 then -- this part and below is part is is not working.
			Status.Value = "Time ran out, nobody won!"
			print("time ran out")
		elseif #Plrs == 1 then
			print("reseting round!")
			Status.Value = "the winner is"..Plrs[1].Name
			table.remove(Plrs,1)
			ChosenMap:Destroy()
			break
		end
	end
	-- cleanup 
	print("cleaning up!")
end

I think it better to use :

Humanoid.Died:Connect(function()
  --remove gameTag
end)

also check if #Plrs == 0 then --no one win --other code end

Edit : make sure died event is outside loop to prevent creating multiple event many many times.

Sorry for the long wait! It seems that its not working, its just doing the same thing

-- define variables
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local StarterGui = game:GetService("StarterGui")
local Status = ReplicatedStorage:WaitForChild("StatusValue")
local MapsFolder = ServerStorage:WaitForChild("Maps")

-- first we need to create the loop
while task.wait() do
	wait(5) -- wait so then the script dosen't crash 
	Status.Value = "Waiting for enough players..."
	repeat task.wait() until game.Players.NumPlayers >= 2
	Status.Value = "Intermission"
	-- Add all players in table in put them in it
	local Plrs = game.Players:GetChildren()
	-- choose a random map and clone it and put it in the workspace. 
	local AvaibleMaps = MapsFolder:GetChildren()
	local ChosenMap = AvaibleMaps[math.random(1,#AvaibleMaps)]
	Status.Value = ChosenMap.Name.."chosen"
	ChosenMapClone = ChosenMap:Clone()
	ChosenMapClone.Parent = game.Workspace
	wait(2)
	-- teleport the players to the map
	-- first make a table with all of the avaible spawn points. 
	local SpawnPositions = ChosenMap:FindFirstChild("SpawnPoints")
	local SpawnPoints = SpawnPositions:GetChildren()
	-- start spawning the players
	for i,player in pairs(Plrs) do
		if player then
			character = player.Character
			if character then
				character:PivotTo(SpawnPoints[1].CFrame)
				table.remove(SpawnPoints,1)
				-- Give them a sword
				local Sword = ServerStorage.Sword:Clone()
				Sword.Parent = player.Backpack
				-- Give them their game tag
				local Gametag = Instance.new("BoolValue")
				Gametag.Name = "GameTag"
				Gametag.Parent = player
			else
				-- there is no avaible character so remove them.
				if not character then
					table.remove(Plrs,i)
					print("character no found")
				end
			end
		end
	end
	-- start the round and add a timer to check and see if someone dies 
	for i = 61,0,-1 do
		wait(1)
		Status.Value = "There are"..i.."seconds remaining."
		for i,player in pairs(Plrs) do
			local character = player.Character
			local humanoid = character:WaitForChild("Humanoid")
			humanoid.Died:Connect(function()
				print("a player died")
				for i, v in pairs(Plrs) do
					if v.Name == player.Name then
						table.remove(Plrs, i)
						player.GameTag:Destroy()
					end
				end
			end)
			if i <= 1 and #Plrs >= 2 then -- this part and below is part is is not working.
				Status.Value = "Time ran out, nobody won!"
				print("time ran out")
			elseif i <= 1 and #Plrs == 1 then
				print("reseting round!")
				Status.Value = "the winner is"..Plrs[1].Name
				table.remove(Plrs,1)
				ChosenMap:Destroy()
			elseif #Plrs == 0 then
				Status.Value = "Everyone died, no one wins!"
				print("everyone died")
				break
			end
		end

	end
	-- cleanup 
	print("cleaning up!")
end

My bad, I meant to reply to the original poster.