Okay so i have been making a map generation code to spawn blocks
but i want to fill in the blocks from under till it reaches a exact position
but for some reason i cant get it to stop duplicating twice
This is how it looks before its filled in
but when i try to fill it in the colors change on each lines like either 2 or 3 times but i dont know why
i dont know how to stop it
local module = {}
local brightColors = {
}
for i = 1, 15 do
table.insert(brightColors, Color3.fromHSV(math.random(), math.random(50, 100)/100, math.random(80, 100)/100))
end
Blacklists = {}
function SpawnBlockDown(Generation)
for i,v in pairs(workspace.AllParts:GetChildren()) do
local OriginPos = v.CFrame
local Blacklisted = false
for i,v in pairs(Blacklists) do
if v.X == OriginPos.X and v.Z == OriginPos.Z then
Blacklisted = true
end
end
if Blacklisted == false then
print(Blacklisted)
task.spawn(function()
task.wait(math.random(8,Generation)/10)
local Times = 0
repeat
local newpart = Instance.new ("Part",workspace.AllParts)
if math.random(1,4) == 3 then
newpart.Color = Color3.fromRGB(150, 150, 150)
newpart.Material = Enum.Material.Rock
else
newpart.Color = brightColors[math.random(1,#brightColors)]
newpart.Material = Enum.Material.SmoothPlastic
end
newpart.Anchored = true
newpart.Size = Vector3.new (5, 5 , 5)
newpart.CFrame = OriginPos + Vector3.new(0,-5,0)
OriginPos = newpart.CFrame
task.wait()
Times = Times + 1
until newpart.Position.Y < 17
print("Ended on " .. Times)
end)
end
end
end
function module:LoadMap(DelayTime:number,CustomSeed,SpawnCharacter:boolean,RandomGeneration)
local GeneralSize = 50
local mapxsize = 25
local mapysize = 30
local mapzsize = 25
local seed
local ExtraPosition = Vector3.new(0,15,0)
if CustomSeed == nil then
seed = math.random(1,100000000)
else
seed = CustomSeed
end
workspace.GenerationData.Seed.Value = seed
local noisescale = 25
local amplitude = 29
local blocksize = 5
local xnoise = 0
local ynoise = 0
local znoise = 0
local AllParts = 0
local AllPartsFolder = script.Value.Value
--print(AllPartsFolder)
for x = 0, mapxsize do
for z = 0, mapzsize do
for y = 0, mapysize do
xnoise = math.noise (x/noisescale, z/noisescale, seed) * amplitude
znoise = math.noise (z/noisescale, x/noisescale, seed) * amplitude
local density = xnoise + znoise + y
if density < 5 and density > 2 then
AllParts = AllParts + 1
end
end
end
end
task.wait()
workspace.GenerationData.MaxParts.Value = tonumber(AllParts)
for x = 0, mapxsize do
for z = 0, mapzsize do
for y = 0, mapysize do
xnoise = math.noise (x/noisescale, z/noisescale, seed) * amplitude
znoise = math.noise (z/noisescale, x/noisescale, seed) * amplitude
local density = xnoise + znoise + y
--print()
if density < 5 and density > 2 then
if RandomGeneration["Enabled"] == true then
task.spawn(function()
task.wait(math.random(8,RandomGeneration["SpawnTime"])/10)
local part = Instance.new ("Part",AllPartsFolder)
if math.random(1,4) == 3 then
part.Color = Color3.fromRGB(150, 150, 150)
part.Material = Enum.Material.Rock
else
part.Color = brightColors[math.random(1,#brightColors)]
part.Material = Enum.Material.SmoothPlastic
end
part.Anchored = true
part.Size = Vector3.new (blocksize, blocksize , blocksize)
part.CFrame = CFrame.new (x*blocksize, y*blocksize + ExtraPosition.Y , z*blocksize)
workspace.GenerationData.CurrentParts.Value = workspace.GenerationData.CurrentParts.Value + 1
local OldPos = part.CFrame
task.spawn(function()
--SpawnBlockDown(OldPos,{BlockSize = blocksize,Folder = AllPartsFolder})
end)
end)
end
end
end
end
if DelayTime ~= nil then
task.wait(tonumber(DelayTime))
end
end
repeat
task.wait()
until workspace.GenerationData.CurrentParts.Value == workspace.GenerationData.MaxParts.Value
SpawnBlockDown(RandomGeneration["SpawnTime"])
if SpawnCharacter then
for i,v in pairs(game.Players:GetPlayers()) do
v:LoadCharacter()
end
game.Players.CharacterAutoLoads = true
end
AllPartsFolder.Parent = workspace
end
return module
This is the module i made
the main part where its breaking is this
function SpawnBlockDown(Generation)
for i,v in pairs(workspace.AllParts:GetChildren()) do
local OriginPos = v.CFrame
local Blacklisted = false
for i,v in pairs(Blacklists) do
if v.X == OriginPos.X and v.Z == OriginPos.Z then
Blacklisted = true
end
end
if Blacklisted == false then
print(Blacklisted)
task.spawn(function()
task.wait(math.random(8,Generation)/10)
local Times = 0
repeat
local newpart = Instance.new ("Part",workspace.AllParts)
if math.random(1,4) == 3 then
newpart.Color = Color3.fromRGB(150, 150, 150)
newpart.Material = Enum.Material.Rock
else
newpart.Color = brightColors[math.random(1,#brightColors)]
newpart.Material = Enum.Material.SmoothPlastic
end
newpart.Anchored = true
newpart.Size = Vector3.new (5, 5 , 5)
newpart.CFrame = OriginPos + Vector3.new(0,-5,0)
OriginPos = newpart.CFrame
task.wait()
Times = Times + 1
until newpart.Position.Y < 17
print("Ended on " .. Times)
end)
end
end
end
Please let me know how i would fix this and why its happening