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
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.
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().
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()
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.
“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.