Invalid argument #2 to 'random' (interval is empty) ERROR

Hey guys, I recently stumbled across an error which now keeps the game at “choosing map” status. The error is this
~ [invalid argument #2 to ‘random’ (interval is empty)~

local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Number = 0
local PositionX = 0
local PositionZ = 0

local Maps = ServerStorage:WaitForChild('Maps'):GetChildren()
local Status = ReplicatedStorage:WaitForChild('Status')

while true do
	
	--Intermission
	
	local Countdown = 30 -- intermission, make this as long as you want
	
	repeat wait(1)
		Countdown = Countdown - 1
		
		Status.Value = 'Intermission : '..Countdown
	until Countdown <= 0
	
	--Choose the map.
	
	Status.Value = 'Choosing Map...'
	
	local ChosenMap = Maps[math.random(1, #Maps)]:Clone()
    wait(0.2)
	local Spawns = ChosenMap:FindFirstChild('Spawns'):GetChildren()


	wait(3) -- little pause, make this as long as you want
	
	Status.Value = 'Map Chosen : '..ChosenMap.Name
	
	wait(3) -- little pause, make this as long as you want
	
	ChosenMap.Parent = workspace
	Status.Value = 'Teleporting Players...'
	
	wait(2) -- little pause, make this as long as you want
	
	--teleport the players
	
	local playersInRound = {} -- track alive players
	local connections = {} -- store connections to disconnect later
	for _, Player in pairs(Players:GetChildren()) do
		if Player.Character and Player.Character:FindFirstChild('Humanoid') then
			local RandomSpawn = Spawns[math.random(1, #Spawns)]
			Player.Character.HumanoidRootPart.CFrame = RandomSpawn.CFrame
			
			

			table.insert(playersInRound, Player) -- add all players to table
			connections[Player.Name] = Player.Character.Humanoid.Died:Connect(function()
				table.remove(playersInRound, table.find(playersInRound, Player))
			end)
		end
	end
	
	connections["Removing"] = game.Players.PlayerRemoving:Connect(function(player) -- remove player from list if they leave
		local ind = table.find(playersInRound, player)
		if ind then
			table.remove(playersInRound, ind)
		end
	end)
	
	Countdown = 5 -- Starting Round In, make this as long as you

Thanks!

3 Likes

That happens when the second argument of math.random is lower than the first. It probably is happening because you have nothing in Spawns or nothing in Maps, so either #Spawns or #Maps is 0. Not sure which, since you didn’t say which line the error was on.

7 Likes

The error was on the line which says

	local ChosenMap = Maps[math.random(1, #Maps)]:Clone()

What should I do to fix this? @rogchamp

3 Likes

That probably means there aren’t any maps. If you check in Studio, is there anything in the maps folder in ServerStorage?

7 Likes

Oh gosh how could I be so silly… thanks…

5 Likes