Issue When Using "Break"

I’m working on a small-prototype for a potential video. It’s basically just a murder type game. The way it works is it just selects a random player, and sets a StringValue placed in ReplicatedStorage to the name of the player. [that value reprents the Current Killer] .

During the for i loop that is used to display the time left before the game ends, I check to see if the killer is still in the game, as well as if all players are still alive. Here is the script:

-- game time
		for i = GAME_TIME,0,-1 do
			statusUpdate(i)
			wait(1)
			if not game.Players[CurrentKiller.Value] then
				break
			end
			
			local playerTable = {}
			
			for i,v in pairs(game.Players:GetPlayers()) do
				if v.PlayerStats.Playing.Value == true then
					if v.Name ~= CurrentKiller.Value then
						table.insert(playerTable, v.Name)
					end
				end
			end
			
			if #playerTable <= 0 then
				for i = 1,#playerTable do -- clear table
					table.remove(playerTable, i)
				end
				break
			else
				for i = 1,#playerTable do -- clear table
					table.remove(playerTable, i)
				end
			end
		end

ISSUE:
For my first testing sessions, I test the killer leaving the game. When I leave the game, the timer stops, but the code doesn’t continue like I want it to. At the top of the code you can see it checks if the player exists in the game, and if not I use break.

This code is below that, which checks for who won [method is a little weird ik];

local winners = {}
		
		for i,v in pairs(game.Players:GetPlayers()) do
			if v.PlayerStats.Playing.Value == true then
				table.insert(winners, v.Name)
			end
		end
		
		if #winners == 1 then
			if winners[1] == CurrentKiller.Value then
				statusUpdate("The Killer Managed To Kill All Players!")
			else
				statusUpdate("Survivors Escaped!")
			end
		elseif #winners > 1 then
			statusUpdate("Survivors Escaped!")
		end
		
		cleanUp()

If anyone knows what could be wrong, please let me know. And yes I already used the Search Query to look for similar issues, but no luck.

1 Like