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

Choose random item off of values?

Asked by 5 years ago

Error: ServerScriptService.Script:20: bad argument #2 to 'random' (interval is empty)

I am trying to make it so it spawns random blocks if the depth is inbetween their maxdepth and minimumdepth

local material = game.ReplicatedStorage:WaitForChild("Blocks"):GetChildren()
local dt = {}

function makeMine(m,a)
    for i = a,1,-1 do 
        wait()
        for i,v in pairs(m:GetChildren()) do
            if v:IsA("BasePart") then
                if v.Name ~= "Spawned" then
                    tick()
                    local depth = v.Position.Y
                    local dt = {}
                    for i,x in pairs(game.ReplicatedStorage.Blocks:GetChildren()) do
                        if x.MaxDepth.Value > depth then
                            if x.MinimumDepth.Value < depth then
                                table.insert(dt,x.Name)
                            end
                        end
                    end
                    local random2 = dt[math.random(1,#dt)]
                    local randomx = game.ReplicatedStorage.Blocks:FindFirstChild(random2)
                    local n = v:Clone()
                    n.Parent = m
                    n.Position = v.Position - Vector3.new(0,v.Size.Y,0)
                    n.BrickColor = randomx.BColor.Value
                    n.Material = randomx.BMat.Value
                    v.Name = "Spawned"
                end
            end
        end
    end
end

while true do
    workspace.Mine:Destroy()
    local m = game.ReplicatedStorage.Mine:Clone()
    m.Parent = workspace
    makeMine(m,15)
    wait(160)
end

Answer this question