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

Choose random parts based off of their values ?

Asked by 5 years ago

I am trying to make it spawn a random block if the depth is between their maxdepth value and minimum depth value each block is a folder in my block folder in replicatedstorage with values inside

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

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
                    local depth = v.Position.Y / v.Size.Y
                    local dt = {}
                    for i,x in pairs(game.ReplicatedStorage.Blocks:GetChildren()) do
                        if x.MaxDepth.Value <= v.Position.Y + 1 then
                            if x.MinimumDepth.Value >= v.Position.Y + 1 then
                                table.insert(dt,x)
                            end
                        end
                    end
                    local random = dt[math.random(1,#dt)]
                    local n = v:Clone()
                    n.Parent = m
                    n.Position = v.Position - Vector3.new(0,v.Size.Y,0)
                    n.BrickColor = random.BColor.Value
                    n.Material = random.BMat.Value
                    v.Name = "Spawned"
                    dt = {}
                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