Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Help with getting map into workspace?

Asked by
FiredDusk 1466 Moderation Voter
7 years ago

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

Log in to vote
4
Answered by
Necrorave 560 Moderation Voter
7 years ago

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!

Ad

Answer this question