How to make my round system repeat?

I’m trying to make my rounds in my game loop, however cause it’s in a while true do the loop is the only part of the script active.

For example:
If a player leaves half way through the loop, the loop won’t stop. And the game will continue running even though there aren’t enough players.

I’m trying to make my rounds loop without sacrificing the rest of the script.

The script:

--[[vars]]--
local rep = game:GetService("ReplicatedStorage")
local guis = game:GetService("StarterGui")
local Players = game:GetService("Players")
local sss = game:GetService("ServerScriptService")

local timeVal = rep.Timer:WaitForChild("TimeVal")
local PlrAmountWarn = guis.PlayerWarn:WaitForChild("NotEnough")

local ShowNEP = rep.NEPEvents:WaitForChild("NotEnoughPlayers")
local RemoveNEP = rep.NEPEvents:WaitForChild("EnoughPlayers")

local SpinGame = rep.Games:WaitForChild("Spinner")
local SpleefGame = rep.Games:WaitForChild("Spleef")

local SpinTimeDefault = 120
local SpinTime = 120

local SpleefTimeDefault = 240
local SpleefTime = 240
--[[vars]]--

local function MapRemove()
	if workspace:FindFirstChild("Spinner") then
		workspace:FindFirstChild("Spinner"):Destroy()
	else
		print("Spinner not found.")
	end
	if workspace:FindFirstChild("Spleef") then
		workspace:FindFirstChild("Spleef"):Destroy()
	else
		print("Spleef not found.")
	end
end

--[[

FOR FUTURE USE. 
CURRENTLY NOT NEEDED.

local function PlayTeam()
	for i, v in pairs(Players:GetChildren()) do
		if v:IsA("Player") then
			v.Team = game.Teams:WaitForChild("Playing")
		end
	end
end
]]

local function TeamPlay()
	for i, v in pairs(Players:GetPlayers()) do
		--the if statement isn't needed, because we use :GetPlayers()
		v.Team = game.Teams:WaitForChild("Playing")
		v:LoadCharacter() 
	end
end

local function TeamLobby()
	for i, v in pairs(Players:GetPlayers()) do
		v.Team = game.Teams:WaitForChild('Lobby')
		v:LoadCharacter()
	end
end

local function Intermission()
	timeVal.Value = "Intermission.. (15)"
	task.wait(1)
	timeVal.Value = "Intermission.. (14)"
	task.wait(1)
	timeVal.Value = "Intermission.. (13)"
	task.wait(1)
	timeVal.Value = "Intermission.. (12)"
	task.wait(1)
	timeVal.Value = "Intermission.. (11)"
	task.wait(1)
	timeVal.Value = "Intermission.. (10)"
	task.wait(1)
	timeVal.Value = "Intermission.. (9)"
	task.wait(1)
	timeVal.Value = "Intermission.. (8)"
	task.wait(1)
	timeVal.Value = "Intermission.. (7)"
	task.wait(1)
	timeVal.Value = "Intermission.. (6)"
	task.wait(1)
	timeVal.Value = "Intermission.. (5)"
	task.wait(1)
	timeVal.Value = "Intermission.. (4)"
	task.wait(1)
	timeVal.Value = "Intermission.. (3)"
	task.wait(1)
	timeVal.Value = "Intermission.. (2)"
	task.wait(1)
	timeVal.Value = "Intermission.. (1)"
	task.wait(1)
	timeVal.Value = "Intermission.. (0)"
	task.wait(1)
end

timeVal.Value = " " -- Setting Timer to default 0

for i, v in pairs(Players:GetChildren()) do
	if v:IsA("Player") then
		v.Team = game.Teams:WaitForChild("Lobby")
	end
end

Players.PlayerAdded:Connect(function(player, teamColor, character) -- Checking when a new player joins.
	print(player.Name .. " joined the game!")
	player.TeamColor = BrickColor.new("Mid gray")
	local players = game:GetService("Players"):GetPlayers()
	if #players >= 2 then
		print("Enough players.")
		RemoveNEP:FireAllClients() -- Removing NEP GUI
		while true do -- the problem
			Intermission()
			timeVal.Value = "Loading..."
			SpinGame:Clone().Parent = workspace
			wait(SpinGame)

			TeamPlay()

			for i, v in pairs(game.Players:GetChildren()) do
				local Character = v.Character or v.CharacterAdd:Wait(2)
				local humanoid = Character:WaitForChild("Humanoid")

				---Then just change there speed here like
				humanoid.WalkSpeed = 0
				humanoid.JumpPower = 80
			end

			task.wait(1)
			timeVal.Value = "Starting... 3"
			task.wait(1)
			timeVal.Value = "Starting... 2"
			task.wait(1)
			timeVal.Value = "Starting... 1"
			task.wait(1)
			timeVal.Value = "Good luck!"

			workspace:FindFirstChild("Spinner").Kill.Spinning.Disabled = false
			task.wait(1)

			local playersOnTeam = game:GetService('Teams').Playing

			timeVal.Value = SpinTimeDefault
			repeat
				timeVal.Value = SpinTime
				SpinTime = SpinTime - 1
				task.wait(1)
			until SpinTime == 0 or #playersOnTeam:GetPlayers() == 1 or #Players:GetPlayers() == 1

			SpinTime = SpinTimeDefault

			TeamLobby()

			for i, v in pairs(game.Players:GetChildren()) do
				local Character = v.Character or v.CharacterAdd:Wait(2)
				local humanoid = Character:WaitForChild("Humanoid")

				---Then just change there speed here like
				humanoid.WalkSpeed = 16
				humanoid.JumpPower = 50
			end

			-- Removing all maps
			MapRemove()

			Intermission()
			timeVal.Value = "Loading..."
			SpleefGame:Clone().Parent = workspace
			wait(SpleefGame)

			TeamPlay()

			task.wait(1)
			timeVal.Value = "Starting... 3"
			task.wait(1)
			timeVal.Value = "Starting... 2"
			task.wait(1)
			timeVal.Value = "Starting... 1"
			task.wait(1)
			timeVal.Value = "Good luck!"

			workspace:FindFirstChild("Spleef").StartingPlat.CanCollide = false
			task.wait(1)

			timeVal.Value = SpleefTimeDefault
			repeat
				timeVal.Value = SpleefTime
				SpleefTime = SpleefTime - 1
				task.wait(1)
			until SpleefTime == 0 or #playersOnTeam:GetPlayers() == 1 or #Players:GetPlayers() == 1

			SpleefTime = SpleefTimeDefault

			TeamLobby()

			-- Removing all maps
			MapRemove()
		end
	else -- mid
		print("Not enough players.")
		MapRemove()
		ShowNEP:FireAllClients() -- Showing NEP GUI
		timeVal.Value = ""
	end
end)

Players.PlayerRemoving:Connect(function(player) -- Checking when a player leaves.
	print(player.Name .. " left the game!")
	local players = game:GetService("Players"):GetPlayers()
	if #players == 1 then
		print("Not enough players.")
		ShowNEP:FireAllClients() -- Showing NEP GUI
		timeVal.Value = ""
		MapRemove()
	end
end)

Please ignore my messy scripting.

Let me know if there’s a way to tell a script to go back up to a line. In this case, the script would go back to line 114. (if that makes sense)

Please, let me know if you have any questions! I will be more than happy to answer them.

All responses are helpful. :slight_smile:

Looking at the code, it doesn’t look like you have a check to see if a game is already running. If someone joins mid-game, then there would be 2 games running at the same time, which would cause problems.

You should move the while true do to after the Players.PlayerRemoving. Every game loop, check if there is enough players. If there isn’t, have something similar to repeat task.wait() until #players >= 2. Also, during the timer loop, have another check for the amount of players. If there isn’t, stop the timer.

If you want to figure out which players are in the game, and which are not, you can have a table that you can add to when a player joins the game during intermission/lobby, and remove from when a player leaves.
If you want to do multiple loops at the same time, you can use coroutines.

Can you provide a code example? (If not I completely understand :slight_smile: )

while true do
local players = game:GetService("Players"):GetPlayers()
if #players < 2 then
repeat task.wait() until #players >= 2
end
-- Game loop code can go here
end

Sorry for the poor formatting, I’m not exactly sure how to indent on the Developer Forum. Also, I didn’t notice you did actually have a check for if the player amount goes under 2, and that you had a table for the amount of players in-game.
#playersOnTeam:GetPlayers() == 1 or #Players:GetPlayers() == 1

If your having a poor time understanding coroutines, you can also use spawn(function() to start new loops.

1 Like

I’m very sorry, I’m trying to understand but, I’m having trouble.
Can you show me how that would work on this section of code?:

Players.PlayerAdded:Connect(function(player, teamColor, character) -- Checking when a new player joins.
	print(player.Name .. " joined the game!")
	player.TeamColor = BrickColor.new("Mid gray")
	local players = game:GetService("Players"):GetPlayers()
	if #players >= 2 then
		print("Enough players.")
		RemoveNEP:FireAllClients() -- Removing NEP GUI
		--Loop start
		Intermission()
		timeVal.Value = "Loading..."
		SpinGame:Clone().Parent = workspace
-- etc

You should completely change the Players.PlayerAdded and Players.PlayerRemoving sections. The loop should start at the end of the script. The GUI code should be in the loop. Full code example:

--[[vars]]--
local rep = game:GetService("ReplicatedStorage")
local guis = game:GetService("StarterGui")
local Players = game:GetService("Players")
local sss = game:GetService("ServerScriptService")

local timeVal = rep.Timer:WaitForChild("TimeVal")
local PlrAmountWarn = guis.PlayerWarn:WaitForChild("NotEnough")

local ShowNEP = rep.NEPEvents:WaitForChild("NotEnoughPlayers")
local RemoveNEP = rep.NEPEvents:WaitForChild("EnoughPlayers")

local SpinGame = rep.Games:WaitForChild("Spinner")
local SpleefGame = rep.Games:WaitForChild("Spleef")

local SpinTimeDefault = 120
local SpinTime = 120

local SpleefTimeDefault = 240
local SpleefTime = 240
--[[vars]]--

local function MapRemove()
	if workspace:FindFirstChild("Spinner") then
		workspace:FindFirstChild("Spinner"):Destroy()
	else
		print("Spinner not found.")
	end
	if workspace:FindFirstChild("Spleef") then
		workspace:FindFirstChild("Spleef"):Destroy()
	else
		print("Spleef not found.")
	end
end

--[[

FOR FUTURE USE. 
CURRENTLY NOT NEEDED.

local function PlayTeam()
	for i, v in pairs(Players:GetChildren()) do
		if v:IsA("Player") then
			v.Team = game.Teams:WaitForChild("Playing")
		end
	end
end
]]

local function TeamPlay()
	for i, v in pairs(Players:GetPlayers()) do
		--the if statement isn't needed, because we use :GetPlayers()
		v.Team = game.Teams:WaitForChild("Playing")
		v:LoadCharacter() 
	end
end

local function TeamLobby()
	for i, v in pairs(Players:GetPlayers()) do
		v.Team = game.Teams:WaitForChild('Lobby')
		v:LoadCharacter()
	end
end

local function Intermission()
	timeVal.Value = "Intermission.. (15)"
	task.wait(1)
	timeVal.Value = "Intermission.. (14)"
	task.wait(1)
	timeVal.Value = "Intermission.. (13)"
	task.wait(1)
	timeVal.Value = "Intermission.. (12)"
	task.wait(1)
	timeVal.Value = "Intermission.. (11)"
	task.wait(1)
	timeVal.Value = "Intermission.. (10)"
	task.wait(1)
	timeVal.Value = "Intermission.. (9)"
	task.wait(1)
	timeVal.Value = "Intermission.. (8)"
	task.wait(1)
	timeVal.Value = "Intermission.. (7)"
	task.wait(1)
	timeVal.Value = "Intermission.. (6)"
	task.wait(1)
	timeVal.Value = "Intermission.. (5)"
	task.wait(1)
	timeVal.Value = "Intermission.. (4)"
	task.wait(1)
	timeVal.Value = "Intermission.. (3)"
	task.wait(1)
	timeVal.Value = "Intermission.. (2)"
	task.wait(1)
	timeVal.Value = "Intermission.. (1)"
	task.wait(1)
	timeVal.Value = "Intermission.. (0)"
	task.wait(1)
end

timeVal.Value = " " -- Setting Timer to default 0

for i, v in pairs(Players:GetChildren()) do
	if v:IsA("Player") then
		v.Team = game.Teams:WaitForChild("Lobby")
	end
end

Players.PlayerAdded:Connect(function(player)
print(player.Name .. " joined the game!")
-- Assign the player to the Lobby team here
end)

Players.PlayerRemoving:Connect(function(player)
print(player.Name .. " left the game!")
-- Remove the player from the currently playing table here
end)

while true do
local players = game:GetService("Players"):GetPlayers()
if #players < 2 then
repeat task.wait() until #players >= 2
end
RemoveNEP:FireAllClients() -- Removing NEP GUI
-- Game loop code goes here
ShowNEP:FireAllClients() -- Showing NEP GUI
end

like this?:

--[[vars]]--
local rep = game:GetService("ReplicatedStorage")
local guis = game:GetService("StarterGui")
local Players = game:GetService("Players")
local sss = game:GetService("ServerScriptService")

local timeVal = rep.Timer:WaitForChild("TimeVal")
local PlrAmountWarn = guis.PlayerWarn:WaitForChild("NotEnough")

local ShowNEP = rep.NEPEvents:WaitForChild("NotEnoughPlayers")
local RemoveNEP = rep.NEPEvents:WaitForChild("EnoughPlayers")

local SpinGame = rep.Games:WaitForChild("Spinner")
local SpleefGame = rep.Games:WaitForChild("Spleef")

local SpinTimeDefault = 120
local SpinTime = 120

local SpleefTimeDefault = 240
local SpleefTime = 240
--[[vars]]--

local function MapRemove()
	if workspace:FindFirstChild("Spinner") then
		workspace:FindFirstChild("Spinner"):Destroy()
	else
		print("Spinner not found.")
	end
	if workspace:FindFirstChild("Spleef") then
		workspace:FindFirstChild("Spleef"):Destroy()
	else
		print("Spleef not found.")
	end
end

--[[

FOR FUTURE USE. 
CURRENTLY NOT NEEDED.

local function PlayTeam()
	for i, v in pairs(Players:GetChildren()) do
		if v:IsA("Player") then
			v.Team = game.Teams:WaitForChild("Playing")
		end
	end
end
]]

local function TeamPlay()
	for i, v in pairs(Players:GetPlayers()) do
		--the if statement isn't needed, because we use :GetPlayers()
		v.Team = game.Teams:WaitForChild("Playing")
		v:LoadCharacter() 
	end
end

local function TeamLobby()
	for i, v in pairs(Players:GetPlayers()) do
		v.Team = game.Teams:WaitForChild('Lobby')
		v:LoadCharacter()
	end
end

local function Intermission()
	timeVal.Value = "Intermission.. (15)"
	task.wait(1)
	timeVal.Value = "Intermission.. (14)"
	task.wait(1)
	timeVal.Value = "Intermission.. (13)"
	task.wait(1)
	timeVal.Value = "Intermission.. (12)"
	task.wait(1)
	timeVal.Value = "Intermission.. (11)"
	task.wait(1)
	timeVal.Value = "Intermission.. (10)"
	task.wait(1)
	timeVal.Value = "Intermission.. (9)"
	task.wait(1)
	timeVal.Value = "Intermission.. (8)"
	task.wait(1)
	timeVal.Value = "Intermission.. (7)"
	task.wait(1)
	timeVal.Value = "Intermission.. (6)"
	task.wait(1)
	timeVal.Value = "Intermission.. (5)"
	task.wait(1)
	timeVal.Value = "Intermission.. (4)"
	task.wait(1)
	timeVal.Value = "Intermission.. (3)"
	task.wait(1)
	timeVal.Value = "Intermission.. (2)"
	task.wait(1)
	timeVal.Value = "Intermission.. (1)"
	task.wait(1)
	timeVal.Value = "Intermission.. (0)"
	task.wait(1)
end

timeVal.Value = " " -- Setting Timer to default 0

for i, v in pairs(Players:GetChildren()) do
	if v:IsA("Player") then
		v.Team = game.Teams:WaitForChild("Lobby")
	end
end

Players.PlayerAdded:Connect(function(player)
	print(player.Name .. " joined the game!")
	player.Team = game.Teams:WaitForChild("Lobby")
end)

Players.PlayerRemoving:Connect(function(player)
	print(player.Name .. " left the game!")
end)

while true do
	local players = game:GetService("Players"):GetPlayers()
	if #players >= 2 then
		repeat task.wait() until #players >= 2
	end
	RemoveNEP:FireAllClients() -- Removing NEP GUI
	Intermission()
	timeVal.Value = "Loading..."
	SpinGame:Clone().Parent = workspace
	wait(SpinGame)
	TeamPlay()
	for i, v in pairs(game.Players:GetChildren()) do
		local Character = v.Character or v.CharacterAdd:Wait(2)
		local humanoid = Character:WaitForChild("Humanoid")
		---Then just change there speed here like
		humanoid.WalkSpeed = 0
		humanoid.JumpPower = 80
	end
	task.wait(1)
	timeVal.Value = "Starting... 3"
	task.wait(1)
	timeVal.Value = "Starting... 2"
	task.wait(1)
	timeVal.Value = "Starting... 1"
	task.wait(1)
	timeVal.Value = "Good luck!"
	workspace:FindFirstChild("Spinner").Kill.Spinning.Disabled = false
	task.wait(1)
	local playersOnTeam = game:GetService('Teams').Playing
	timeVal.Value = SpinTimeDefault
	repeat
		timeVal.Value = SpinTime
		SpinTime = SpinTime - 1
		task.wait(1)
	until SpinTime == 0 or #playersOnTeam:GetPlayers() == 1 or #Players:GetPlayers() == 1
	SpinTime = SpinTimeDefault
	TeamLobby()
	for i, v in pairs(game.Players:GetChildren()) do
		local Character = v.Character or v.CharacterAdd:Wait(2)
		local humanoid = Character:WaitForChild("Humanoid")
		---Then just change there speed here like
		humanoid.WalkSpeed = 16
		humanoid.JumpPower = 50
	end
	-- Removing all maps
	MapRemove()
	Intermission()
	timeVal.Value = "Loading..."
	SpleefGame:Clone().Parent = workspace
	wait(SpleefGame)
	TeamPlay()
	task.wait(1)
	timeVal.Value = "Starting... 3"
	task.wait(1)
	timeVal.Value = "Starting... 2"
	task.wait(1)
	timeVal.Value = "Starting... 1"
	task.wait(1)
	timeVal.Value = "Good luck!"
	workspace:FindFirstChild("Spleef").StartingPlat.CanCollide = false
	task.wait(1)
	timeVal.Value = SpleefTimeDefault
	repeat
		timeVal.Value = SpleefTime
		SpleefTime = SpleefTime - 1
		task.wait(1)
	until SpleefTime == 0 or #playersOnTeam:GetPlayers() == 1 or #Players:GetPlayers() == 1
	SpleefTime = SpleefTimeDefault
	TeamLobby()
	-- Removing all maps
	MapRemove()
	ShowNEP:FireAllClients() -- Showing NEP GUI
end

That should work, but you can also test it in your own game to make sure it works.

Okay I did some testing and here’s what I found:

  1. If someone leaves the game the loop doesn’t stop.
  2. The NEP (Not enough players) GUI does not disappear until the end of the loop.
  3. The NEP GUI also does not re-appear if there are not enough players.

Please help. :slight_smile:

For the NEP GUI, you can have it appear at the start of the loop inside of the players check, and then remove it once enough players is reached. However, I do not know why the loop isn’t stopping, it should stop the timer and then wait for enough players at the start of the loop. What do you mean by “not stopping”? Are you talking about the timer or the entire loop?

1 Like

I’m talking about the entire loop. When a player leaves the game keeps going.

So are you saying that the check for enough players at the beginning of the loop is not working?

yes:

--[[vars]]--
local rep = game:GetService("ReplicatedStorage")
local guis = game:GetService("StarterGui")
local Players = game:GetService("Players")
local sss = game:GetService("ServerScriptService")

local timeVal = rep.Timer:WaitForChild("TimeVal")
local PlrAmountWarn = guis.PlayerWarn:WaitForChild("NotEnough")

local ShowNEP = rep.NEPEvents:WaitForChild("NotEnoughPlayers")
local RemoveNEP = rep.NEPEvents:WaitForChild("EnoughPlayers")

local SpinGame = rep.Games:WaitForChild("Spinner")
local SpleefGame = rep.Games:WaitForChild("Spleef")

local SpinTimeDefault = 120
local SpinTime = 120

local SpleefTimeDefault = 240
local SpleefTime = 240
--[[vars]]--

local function MapRemove()
	if workspace:FindFirstChild("Spinner") then
		workspace:FindFirstChild("Spinner"):Destroy()
	else
		print("Spinner not found.")
	end
	if workspace:FindFirstChild("Spleef") then
		workspace:FindFirstChild("Spleef"):Destroy()
	else
		print("Spleef not found.")
	end
end

--[[

FOR FUTURE USE. 
CURRENTLY NOT NEEDED.

local function PlayTeam()
	for i, v in pairs(Players:GetChildren()) do
		if v:IsA("Player") then
			v.Team = game.Teams:WaitForChild("Playing")
		end
	end
end
]]

local function TeamPlay()
	for i, v in pairs(Players:GetPlayers()) do
		--the if statement isn't needed, because we use :GetPlayers()
		v.Team = game.Teams:WaitForChild("Playing")
		v:LoadCharacter() 
	end
end

local function TeamLobby()
	for i, v in pairs(Players:GetPlayers()) do
		v.Team = game.Teams:WaitForChild('Lobby')
		v:LoadCharacter()
	end
end

local function Intermission()
	timeVal.Value = "Intermission.. (15)"
	task.wait(1)
	timeVal.Value = "Intermission.. (14)"
	task.wait(1)
	timeVal.Value = "Intermission.. (13)"
	task.wait(1)
	timeVal.Value = "Intermission.. (12)"
	task.wait(1)
	timeVal.Value = "Intermission.. (11)"
	task.wait(1)
	timeVal.Value = "Intermission.. (10)"
	task.wait(1)
	timeVal.Value = "Intermission.. (9)"
	task.wait(1)
	timeVal.Value = "Intermission.. (8)"
	task.wait(1)
	timeVal.Value = "Intermission.. (7)"
	task.wait(1)
	timeVal.Value = "Intermission.. (6)"
	task.wait(1)
	timeVal.Value = "Intermission.. (5)"
	task.wait(1)
	timeVal.Value = "Intermission.. (4)"
	task.wait(1)
	timeVal.Value = "Intermission.. (3)"
	task.wait(1)
	timeVal.Value = "Intermission.. (2)"
	task.wait(1)
	timeVal.Value = "Intermission.. (1)"
	task.wait(1)
	timeVal.Value = "Intermission.. (0)"
	task.wait(1)
end

timeVal.Value = " " -- Setting Timer to default 0

for i, v in pairs(Players:GetChildren()) do
	if v:IsA("Player") then
		v.Team = game.Teams:WaitForChild("Lobby")
	end
end

Players.PlayerAdded:Connect(function(player)
	print(player.Name .. " joined the game!")
	player.Team = game.Teams:WaitForChild("Lobby")
end)

Players.PlayerRemoving:Connect(function(player)
	print(player.Name .. " left the game!")
end)

while true do
	local players = game:GetService("Players"):GetPlayers()
	if #players >= 2 then
		repeat task.wait() until #players >= 2
	end
	RemoveNEP:FireAllClients() -- Removing NEP GUI
	Intermission()
	timeVal.Value = "Loading..."
	SpinGame:Clone().Parent = workspace
	wait(SpinGame)
	TeamPlay()
	for i, v in pairs(game.Players:GetChildren()) do
		local Character = v.Character or v.CharacterAdd:Wait(2)
		local humanoid = Character:WaitForChild("Humanoid")
		---Then just change there speed here like
		humanoid.WalkSpeed = 0
		humanoid.JumpPower = 80
	end
	task.wait(1)
	timeVal.Value = "Starting... 3"
	task.wait(1)
	timeVal.Value = "Starting... 2"
	task.wait(1)
	timeVal.Value = "Starting... 1"
	task.wait(1)
	timeVal.Value = "Good luck!"
	workspace:FindFirstChild("Spinner").Kill.Spinning.Disabled = false
	task.wait(1)
	local playersOnTeam = game:GetService('Teams').Playing
	timeVal.Value = SpinTimeDefault
	repeat
		timeVal.Value = SpinTime
		SpinTime = SpinTime - 1
		task.wait(1)
	until SpinTime == 0 or #playersOnTeam:GetPlayers() == 1 or #Players:GetPlayers() == 1
	SpinTime = SpinTimeDefault
	TeamLobby()
	for i, v in pairs(game.Players:GetChildren()) do
		local Character = v.Character or v.CharacterAdd:Wait(2)
		local humanoid = Character:WaitForChild("Humanoid")
		---Then just change there speed here like
		humanoid.WalkSpeed = 16
		humanoid.JumpPower = 50
	end
	-- Removing all maps
	MapRemove()
	Intermission()
	timeVal.Value = "Loading..."
	SpleefGame:Clone().Parent = workspace
	wait(SpleefGame)
	TeamPlay()
	task.wait(1)
	timeVal.Value = "Starting... 3"
	task.wait(1)
	timeVal.Value = "Starting... 2"
	task.wait(1)
	timeVal.Value = "Starting... 1"
	task.wait(1)
	timeVal.Value = "Good luck!"
	workspace:FindFirstChild("Spleef").StartingPlat.CanCollide = false
	task.wait(1)
	timeVal.Value = SpleefTimeDefault
	repeat
		timeVal.Value = SpleefTime
		SpleefTime = SpleefTime - 1
		task.wait(1)
	until SpleefTime == 0 or #playersOnTeam:GetPlayers() == 1 or #Players:GetPlayers() == 1
	SpleefTime = SpleefTimeDefault
	TeamLobby()
	-- Removing all maps
	MapRemove()
	ShowNEP:FireAllClients() -- Showing NEP GUI
end

It’s only checking how many players are in the game at the start of the loop.

Sorry, the code is just faulty. There is no # before game:GetService("Players"):GetPlayers(). If you add the #, the code should work fine.

So what do I do? (If there is anything I can do)

You can fix the code by adding a # before game:GetService("Players"):GetPlayers(). Here is the fixed code:

local players = #game:GetService("Players"):GetPlayers()
	if #players >= 2 then
		repeat task.wait() until #players >= 2
	end
1 Like

ServerScriptService.RoundScript:119: attempt to get length of a number value - Server - RoundScript:119

Why hasn’t anyone mentioned the Intermission function lol.

local function Intermission()
    for i = 15, 0, -1 do
        timeVal.Value = "Intermission .. (" .. i .. ")"
        task.wait(1)
    end
end
2 Likes

This error is happening because you’re defining the players variable here as the amount of players. @LoveingLiamGuy’s code was a bit wrong. It should be:

local players = game:GetService("Players")
if #players:GetPlayers() <= 2 then
    -- not enough to start
    repeat task.wait() until #players:GetPlayers() > 2
end

Thank you so much! I was experiencing a few problems with that so I gave up on it at the time and made the temp fix.