New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
Log in to vote

bad argument #2 to 'random' (interval is empty) , how do i fix this?

Asked by 3 months ago

this is a localscript located inside a textbutton.

the local script is supposed to activate when the button is pressed, however i've run into an error that says bad argument. (LINE 11) but I don't see any errors.

button = script.Parent
player = game.Players.LocalPlayer


local menu = player.PlayerGui:WaitForChild("Menu")
menu.MainFrame:TweenPosition(, 0, 0, 0),"Out", "Quart", 2)
local mapstorage = game.Workspace.mapStorage

local mapsinserverstorage = game:GetService('ServerStorage'):GetChildren()
    local chosenmap = mapsinserverstorage[math.random(1, #mapsinserverstorage)]
    chosenmap:Clone().Parent = mapstorage
    local spawns = chosenmap:WaitForChild("Spawns"):GetChildren()
    local allspawns = math.random(1, #spawns)
    local randomspawn = spawns[allspawns]

    if #spawns > 0 then

    player.Character.HumanoidRootPart.CFrame =, math.random)

    local pistol = game.ReplicatedStorage.Weapons.Pistol
    local cPistol = pistol:Clone()
    cPistol.Parent = player.Backpack

    local sledge = game.ReplicatedStorage.Utility.Sledge
    local cSledge = sledge:Clone()
    cSledge.Parent = player.Backpack


Answer this question