How can i break a for count = 30, 1, -1 do if either player1 or player2 dies

how can i make break the for count = 30, 1, -1 do if either player1 or player2 dies.

  1. What do you want to achieve? Keep it simple and clear!
    Just wanting to know how i can break the *for i = * variable whenever player1 or player2 dies

  2. What is the issue? Include screenshots / videos if possible!
    I just don’t know how i can do this. I’ve tried everything!

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried the studio Ai and tried to find some For i, youtube tutorials, but none really have on how to break the for i

for count = 30, 1, -1 do 
				String.Value = tostring(count.. " seconds left")
				task.wait(1)
			if String.Value == "1 seconds left" then
				String.Value = "The duel has ended! Randomly choosing winner"
					destroyToolsAndDecideWinner()
					DoCheck()
				end
			end

IF YOU ARE INTRESTED IN THE WHOLE CODE FOR WHAT IM TRYING TO SAY

local Players = game:GetService("Players")
local DuelInProgress = false
local String = game.ReplicatedStorage.Status
local RunService = game:GetService("RunService")

local PlayerCount = 0
local InIntermission = false
local countdown = 240

local GameSettings = {
	GameSpeed = 240 -- four minutes
}

local function destroyToolsAndDecideWinner() 

	local player1 = Players:FindFirstChild("player1")
	local player2 = Players:FindFirstChild("player2")

	if player1 and player2 then
		local backpack1 = player1:FindFirstChild("Backpack")
		local backpack2 = player2:FindFirstChild("Backpack")

		if backpack1 and backpack2 then

			for _, tool in ipairs(backpack1:GetChildren()) do
				if tool:IsA("Tool") then
					tool:Destroy()
				end
			end


			for _, tool in ipairs(backpack2:GetChildren()) do
				if tool:IsA("Tool") then
					tool:Destroy()
				end
			end



			local winner = math.random(1, 2)
			if winner == 1 then
				player2.Character.Humanoid.Health = 0 


			else
				player1.Character.Humanoid.Health = 0

			end

		end
	end
end



local function DoCheck()
	if PlayerCount >= 2 and not InIntermission then
		local function StartDuelGameMode()	-- Starts Duel

			if DuelInProgress then
				print("A duel is already in progress.")
				String.Value = "Duel in progress"
				return
			end


			DuelInProgress = true


			local allPlayers = Players:GetPlayers()



			local player1 = allPlayers[math.random(1, #allPlayers)]
			local player2 = allPlayers[math.random(1, #allPlayers)]


			while player1 == player2 do
				player2 = allPlayers[math.random(1, #allPlayers)]
			end

			for count = 5, 1, -1 do 
				String.Value = tostring(count)
				task.wait(1)
			end


			String.Value = "A duel has started between " .. player1.Name .. " and " .. player2.Name

			player1.Character:MoveTo(workspace.GameSpawns.Player1Spawn.Position)

			player2.Character:MoveTo(workspace.GameSpawns.Player2Spawn.Position)

			local Tool = game.ServerStorage.Tools.Sponge
			Tool:Clone().Parent =  player1.Backpack
			Tool:Clone().Parent =  player2.Backpack

wait(3.2)


			for count = 30, 1, -1 do 
				String.Value = tostring(count.. " seconds left")
				task.wait(1)
			if String.Value == "1 seconds left" then
				String.Value = "The duel has ended! Randomly choosing winner"
					destroyToolsAndDecideWinner()
					DoCheck()
				end
			end
		

			
			


			


	
			
		
end


		StartDuelGameMode()

	

		local function restartGame() -- Restart Duel
			local player1 = Players:FindFirstChild("player1")
			local player2 = Players:FindFirstChild("player2")

			if player1.Character.Humanoid.Health > 0 or player2.Character.Humanoid.Health > 0 then
			
			
				DuelInProgress = false
				String.Value = "Reseting..."

				return DoCheck()
			end
		end
		
	elseif PlayerCount < 2 and InIntermission then
		InIntermission = false
		String.Value = "Not Enough Players to start."
	end
end

local function onPlayerDeath(player)
	local player1 = Players:FindFirstChild("player1")
	local player2 = Players:FindFirstChild("player2")

	if player == player1 then
		String.Value = player2.Name .. " wins!"
		player1.leaderstats.Deaths.Value =  player1.leaderstats.Deaths.Value + 1
		player2.leaderstats.Wins.Value =  player2.leaderstats.Wins.Value + 1
	elseif player == player2 then
		String.Value = player1.Name .. " wins!"
		player2.leaderstats.Deaths.Value =  player2.leaderstats.Deaths.Value + 1
		player1.leaderstats.Wins.Value =  player1.leaderstats.Wins.Value + 1
	end

	player.Character.Humanoid.Died:Disconnect()


	player1.Character.Humanoid.Died:Connect(function()



		onPlayerDeath(player1)
	end)

	player2.Character.Humanoid.Died:Connect(function()


		onPlayerDeath(player2)
	end)

end
Players.PlayerAdded:Connect(function(Player)
	PlayerCount += 1
	DoCheck()
end)

Players.PlayerRemoving:Connect(function(Player)
	PlayerCount -= 1
	DoCheck()
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Just use break and the rest of the script will continue as normal