The round does not end if there are no players in the team

So i was trying to make an round system script and it works so far but if there’s no hiders(Team) the round doesn’t end and i tried everything but it still doesn’t work i hope someone could give me a tip to get it working Thanks (yes I’m new to scripting kinda, and ignore the grammatic errors i wrote the script very late, i think it was 3am lol)

Full script:

--// Variables

local Lobby = game.Workspace.Lobby
local Maps = game.ReplicatedStorage.Maps:GetChildren()
local Status = game.ReplicatedStorage.Status
local PlR = game.Players
local ReplicatedService = game:GetService("ServerStorage")
local LaserGune = ReplicatedService.HyperlaserGun
local CloneGun = LaserGune:Clone()
local userInputService = game:GetService("UserInputService")
local isUsingVR = userInputService.VREnabled

local ReplicatedServices = game:GetService("ReplicatedStorage")
local teamService = game:GetService("Teams")
local HidersTeam = teamService:WaitForChild("Hiders")
local SeekerTeam = teamService:WaitForChild("Seeker")



--// Game Loop

while true do
	
	--// Intermission
	
	for i = 15, 0, -1 do
		Status.Value = "Intermission: "..i
		task.wait(1)
	end
	
	
	--// Map Selector
	
	local ChosenMap = Maps[math.random(1, #Maps)]
	local ClonedMap = ChosenMap:Clone()
	
	ClonedMap.Parent = game.Workspace
	Status.Value = "Map: "..ClonedMap.Name
	
	
	task.wait(3)
	
	local chosenPlayer = game.Players:GetPlayers()[math.random(1)]
	Status.Value = "Seeker is: "..chosenPlayer.Name
	
	task.wait(5)
	
	-- Teleports to Map
	
	for i, Player in pairs(game.Players:GetPlayers()) do
	
		local Chracter = Player.Character
		
		if Chracter then
			local HumanoidRootPart = Chracter.HumanoidRootPart
			
			HumanoidRootPart.CFrame = ClonedMap.TeleportPoint.CFrame
			chosenPlayer.Character.HumanoidRootPart.CFrame = Lobby.TeleportPoint.CFrame
			Player.Team = HidersTeam
		end
	end
	

	
	--// Game Seek

	
	task.wait(3)
	
	for i = 3, 0, -1 do
		Status.Value = "Seeker is coming in: "..i
		task.wait(1)
	end
	
	if chosenPlayer then
		chosenPlayer.Character.HumanoidRootPart.CFrame = ClonedMap.TeleportPoint.CFrame
		CloneGun.Parent = chosenPlayer.Character
		chosenPlayer.Team = SeekerTeam
	end
	
	
	
	--// Game Time
	
	local Time = 30
	
	for i = Time, 0, -1 do
		Status.Value = "Survive: "..i
		task.wait(1)
		
		if HidersTeam == 0 then
			Time = 0
			i = 0
		end
	end


	
	
	-- Teleports to Lobby
	
	for i, Player in pairs(game.Players:GetPlayers()) do
		
		local Character = Player.Character
		
		if Character then
			
			local HumanoidRootPart = Character.HumanoidRootPart
			
			HumanoidRootPart.CFrame = Lobby.TeleportPoint.CFrame
		end
		
	end
	
	
	
	
	CloneGun:Destroy()
	ClonedMap:Destroy()
end

The problem

	--// Game Time
	
	local Time = 30
	
	for i = Time, 0, -1 do
		Status.Value = "Survive: "..i
		task.wait(1)
		
		if HidersTeam == 0 then
			Time = 0
			i = 0
		end
	end

and yes all scripts are set up only this won’t work

Thanks for helping

local AmountOfHiders = HidersTeam:GetPlayers()
print(#AmountOfHiders)

if #AmountOfHiders == 0 then
    Time = 0
end

So it kinda works it print’s all successfully but if AmountOfHiders are 0 it just spams and the timer doesn’t end and just keep going
Bild_2024-03-27_115554540

You need to break out of the loop if either time == 0 or AmountOfHiders == 0 is true.

local AmountOfHiders = HidersTeam:GetPlayers()
print(#AmountOfHiders)

if #AmountOfHiders == 0 then
    Time = 0
     break
end

You gotta break out of the loop to make it stop when there arent any players left.

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