Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help with getting map into workspace?

I am trying to make a minigames game and this is a function I made to clone a random map into workspace but I get this error: Workspace.Main:3: bad argument #2 to 'random' (interval is empty)

function GetMap()
	local MapsFolder = game.ReplicatedStorage.Maps:GetChildren()
	local SelectMap = math.random(1, #MapsFolder)
	local SelectedMap = MapsFolder[SelectMap]:Clone()
	SelectedMap.Parent = game.Workspace
	SelectedMap.Name = "Map"
end

1 answer

✓ Accepted answer

It looks like your MapsFolder is empty.

When you try to use GetChildren() and there is no children, it will return nil.

So when you try to use #MapsFolder, it will also be nil. Which causes an error in math.random()

Let me know if you have any other questions!

This discussion is preserved as it was. New answers, comments, and votes are closed.