Round keeps restarting again and again

hi, i made a round system that chooses random players to be a killer or a survivor
and i tried to detect if all survivors died but the round kept restarting

can someone help me?

local function detect_if_all_survivor_alive(player)
	if #playersinRound == 0 then
		values_folder.time.Value = 0
		values_folder.killer_won.Value = true
		values_folder.survivor_won.Value = false
		values_folder.survivors_died.Value = true
		print("no players!")
	else
		print("der is players :(")
		return
	end
end

local function system(player)
	task.wait(3)
	debounce_check_if_killer_is_alive = false
	print("start again")
	values_folder.time.Value = 120
	
	soundgroup.lobby_theme:Play()
	
	local playersinRound = {}
	local connections = {}
	
	local chosen = plrs:GetChildren()[math.random(1, #plrs:GetChildren())]
	
	values_folder.teleport.Value = false
	values_folder.blackout.Value = false
	values_folder.inRound.Value = false
	values_folder.can_show.Value = true
	
	values_folder.survivor_won = false
	values_folder.survivors_died.Value = false
	values_folder.killer_won.Value = false
	
	values_folder.inLobby.Value = true
	values_folder.killer_user.Value = "none"
	Lobby_Music_Tween_1:Play()
	
	killer = {}
		
	local player = game:GetService("Players"):GetPlayers()[1]
	
	if chosen:WaitForChild("values_folder").isKiller.Value == true and chosen:WaitForChild("values_folder").isSurvivor.Value == false then
		if not badgeservice:UserHasBadgeAsync(chosen.UserId,2144098131) then
			badgeservice:AwardBadge(chosen.UserId, 2144098131)
		else
			print(chosen.Name.."already has the killer badge")
			return
		end
	end
	
	task.wait()
	
	
	if player:FindFirstChild("values_folder") then
		player:WaitForChild("values_folder").isSurvivor.Value = false
	end
	
	if chosen:FindFirstChild("values_folder") then
		chosen:WaitForChild("values_folder").isKiller.Value = false
	end
	
	repeat task.wait() until game.Players.NumPlayers >= required_player
	
	if game.Players.NumPlayers >= required_player then
		soundgroup.tick:Play()
		repeat task.wait(1) values_folder.time.Value -= 1; remotes_folder.change_text:FireAllClients(); remotes_folder.change_text:FireAllClients(); until
		values_folder.time.Value <= 0

		Lobby_Music_Tween_0:Play()
		values_folder.inLobby.Value = false

		if values_folder.time.Value == 0 then
			task.wait(1)
			soundgroup.tick:Stop()
			print("round starting")
			soundgroup.clock_chime:Play()
		end

		task.wait(12)
		print("starting")
		
		values_folder.killer_user.Value = chosen.Name
		print("killer is "..values_folder.killer_user.Value)

		chosen:WaitForChild("values_folder").isKiller.Value = true
		chosen:WaitForChild("values_folder").isSurvivor.Value = false
		
		for _, player in pairs(game.Players:GetPlayers()) do
			if player:WaitForChild("values_folder").isSurvivor.Value == true then
				values_folder.survivors_inGame.Value = values_folder.survivors_inGame + 1
			end
		end
		
		if player:WaitForChild("values_folder").isSurvivor.Value == false and player.values_folder.isKiller.Value == false then
			player:WaitForChild("values_folder").isSurvivor.Value = true
			print(player.Name.." is survivor")
		end


		task.wait(7)
		values_folder.time.Value = 120
		--values_folder.teleport.Value = true

		for i, player in pairs(game.Players:GetPlayers()) do
			if player.Character and player.Character:FindFirstChild("Humanoid") then
				if player:FindFirstChild("values_folder").isSurvivor.Value == true then
					local rootpart = player.Character:WaitForChild("HumanoidRootPart")
					rootpart.CFrame = workspace.game.spawn.CFrame
					table.insert(playersinRound, player)
					print(#playersinRound)
					connections[player.Name] = player.Character.Humanoid.Died:Connect(function()
						if player:WaitForChild("values_folder").isSurvivor.Value == true then
							removePlayerfromRound(player)
						end
					end)

					if player:WaitForChild("values_folder").isKiller.Value == true then
						player.Character:WaitForChild("HumanoidRootPart").CFrame = workspace.game.killer_spawn.CFrame
					end
				end
			end
		end

		task.wait(19)
		game_folder.values.inRound.Value = true
		game_folder.values.round_start.Value = true
		task.wait(2)
		
		for i,killer in pairs(game.Players:GetPlayers()) do
			if killer:FindFirstChild("values_folder").isKiller.Value == true then
				local axe_killer_clone = game_folder.AxeKiller:Clone()
				local weld_axe = Instance.new("Weld")
				
				local character = killer.Character
				local RightHand = character:WaitForChild("RightHand")
				
				local RightGripAttachment = RightHand:WaitForChild("RightGripAttachment")
				weld_axe.Part0 = RightHand
				
				axe_killer_clone.Parent = character
				weld_axe.C0 = CFrame.new(0,0.1,0)
				
				weld_axe.Part0 = RightHand
				weld_axe.Part1 = axe_killer_clone
			end
		end
		
		for i, player in pairs(game.Players:GetPlayers()) do
			if player.Character and player.Character:WaitForChild("Humanoid") then
				player.Character:WaitForChild("Humanoid").Died:Connect(function()
					if player:WaitForChild("values_folder").isSurvivor.Value == true and player:WaitForChild("values_folder").isSurvivor.Value == false then
						values_folder.survivors_died.Value = values_folder.survivors_died.Value + 1
						values_folder.survivors_inGame.Value = values_folder.survivors_inGame - 1
						player:WaitForChild("values_folder").died.Value = true
						print("1 survivor died")
					end
				end)
				player.Character:WaitForChild("Humanoid").Died:Connect(function()
					if player:WaitForChild("values_folder").isKiller.Value == true and player:WaitForChild("values_folder").isSurvivor.Value == false then
						values_folder.survivor_won.Value = true
					end
				end)
			end
		end
		
		
		repeat detect_if_all_survivor_alive() task.wait(1) values_folder.time.Value -= 1 until
		values_folder.time.Value <= 0
		
		values_folder.inRound.Value = false

		for i, playersinRound in pairs(playersinRound) do
			playersinRound:Disconnect()
		end

		task.wait(4)
		values_folder.blackout.Value = true
		task.wait(2)
		
		for i, player in pairs(game.Players:GetPlayers()) do
			if player.Character and player.Character:FindFirstChild("Humanoid") then
				local rootpart = player.Character:WaitForChild("HumanoidRootPart")
				
				rootpart.CFrame = workspace.game.lobby_spawn.CFrame
			elseif game.Players.NumPlayers >= 1 then
				print("one player??")
			end
			
			if values_folder.killer_won.Value == true and values_folder.survivor_won.Value == false then
				values_folder.killer_won.Value = true
				values_folder.survivor_won.Value = false
			end
			
			if values_folder.survivor_won.Value == true and values_folder.killer_won.Value == false then
				values_folder.killer_won.Value = false
				values_folder.survivor_won.Value = true
				
				if player:WaitForChild("values_folder").died.Value == false and player:WaitForChild("values_folder").isSurvivor.Value == true and player:WaitForChild("values_folder").isKiller.Value == true then
					if not badgeservice:UserHasBadgeAsync(player.UserId,2144098065) then
						badgeservice:AwardBadge(player.UserId, 2144098065)
					else
						print(player.Name.." already has the survive badge")
					end
				end
			end
			task.wait(12)
		end
	end
end

nevermind guys I found a solution!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.