23:33:31.321 ServerScriptService.Game.Control:7: invalid argument #2 to 'random' (interval is empty) - Server - Control:7 23:33:31.322 Stack Begin

  23:33:31.321  ServerScriptService.Game.Control:7: invalid argument #2 to 'random' (interval is empty)  -  Server - Control:7
  23:33:31.322  Stack Begin  -  Studio
  23:33:31.322  Script 'ServerScriptService.Game.Control', Line 7 - function StartGame  -  Studio - Control:7
  23:33:31.323  Script 'ServerScriptService.Game.Game', Line 6  -  Studio - Game:6
  23:33:31.323  Stack End  -  Studio
local module = {}

module.GameStarted = false

function module:StartGame()
	local Maps = game:GetService("ServerStorage"):WaitForChild("Maps"):GetChildren()
	local Map = Maps[math.random(1, #Maps)]
	
	Map:Clone()
	Map.Parent = workspace
	for i, v in pairs(Map:GetChildren()) do
		v.Parent = workspace
	end
	
	local spawns = {} for i, v in pairs(workspace.Spawns:GetChildren()) do
		table.insert(spawns, v)
	end
	
	for i, v in pairs(workspace.CharactersInLobby:GetChildren()) do
		v.Parent = workspace.CharactersInGame
		v.HumanoidRootPart.Position = spawns[math.random(1, #spawns)]
		v.Humanoid.WalkSpeed = 0 v.Humanoid.JumpPower = 0
		
		task.wait(3)
		
		v.Humanoid.WalkSpeed = 24 v.Humanoid.JumpPower = 70
	end
end

function module:EndGame()
	
end

return module

1 Like

try to seperate your code more, it makes it harder to read and prone to more bugs

maps seems to be 0, which would cause this error.

2 Likes

I thought the same thing, but

Screenshot 2022-10-09 234433

Thier’s no other scripts that mess around or do anything to the map so I’m kind of stuck

I’ve just tried your code and it works for me, so the only other thing must be another script is changing something. Check all script and see if they alter the Maps folder in any way.

Add

print(#Maps)

before doing the math.random.

1 Like

Sir that finger looks like something else

1 Like

Change

local Map = Maps[math.random(1, #Maps)]

to

local Map = Maps:GetChildren()[math.random(1, #Maps)]

With what you have currently, math.random gives you a number, and then you are looking inside Maps for an object with the name of the same number e.g. “3”.
But you are wanting to get the object with the index of that number, meaning we need an array of the children of Maps which we can get with :GetChildren().

EDIT: added explanation

That’s literally what his is doing, so there is no difference. It would be different if he didn’t use :GetChildren()

Oops. My bad, didn’t see that.

When you clone the map, you aren’t giving it a new variable,
meaning that its taking the original map (the uncloned one) and just using that.
So change line 9 to like local newMap = Map:Clone()

1 Like

Im believe you’re not giving us the right script. Also, I hope you thought this one out over and over before making a dev forum post because I hate when people just wait for people to solve their problems.

stop making me look dirty minded

1 Like

I had to do something, so I didn’t respond to any replies yet…

Like I said, their aren’t other scripts in my game that I’ve put in it that does anything with the maps

Where is the modulescript located at? It may not even reach serverstorage.
And how is it required?

It’s in SSS, and its required by a script in SSS.

It might be that the contents of the folder aren’t instanced right away on server instantiation.

You’d have to keep a list of name-based references of all the maps and WaitForChild through that table upon server instantiation.

“interval is empty” means that you tried to do math.random(a, b) where b is smaller than a. When you’re doing :GetChildren(), it isn’t actually getting any children.

When does the code run? Does it run as soon as the game starts? It might not have enough time to actually load the children. Add a manual task.wait(3) before the code runs and see if it works. If so, that means you’re gonna have to wait for them to load.

1 Like

Check if you forgot to add your Map into Maps.