In ReplicatedStorage there is a folder called Blocks, and inside of the folder there are folders that are the title of blocks with values that consist of their brickcolor, material, maxdepth spawn, and minimumdepth spawn
i am trying to make a script that will insert a random block depending on its max/minimum depth
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
