function DeleteTerrain(model)
-- Find ALL descendants named "_D", not just direct children
local deleteParts = model:GetDescendants()
for _, descendant in ipairs(deleteParts) do
if descendant.Name == "_D" and descendant:IsA("BasePart") then
delay(5, function()
pcall(function()
workspace.Terrain:FillBlock(descendant.CFrame, descendant.Size, Enum.Material.Air)
end)
-- Consider waiting for the operation to complete before proceeding
descendant:Destroy()
end)
end
end
-- Return a completion signal
return true
end
-- Load presets from ReplicatedStorage
function loadPresets()
local terrainObjectsFolder = ReplicatedStorage:FindFirstChild("TerrainObjects")
if not terrainObjectsFolder then
return
end
local function loadCategory(categoryName)
local categoryFolder = terrainObjectsFolder:FindFirstChild(categoryName)
if categoryFolder then
presets[string.lower(categoryName)] = {} -- Clear existing presets for this category
for _, model in ipairs(categoryFolder:GetChildren()) do
-- Ensure it's a model with a PrimaryPart and not a script or other instance
if model:IsA("Model") and model.PrimaryPart then
-- Clean model by removing any parts named "_D"
DeleteTerrain(model)
table.insert(presets[string.lower(categoryName)], model)
end
end
end
end
loadCategory("Trees")
loadCategory("Rocks")
loadCategory("Homes")
end
the excerpt is from my terrain generation script.
ffunction makeChunk(chunkX, chunkZ)
... -- terrain generation
for x = 0, chunkScale-1 do
for z = 0, chunkScale-1 do
... -- terrain generation
-- Try placing a rock
if not placed and #presets.rocks > 0 and math.random() < rockDensity then
placeObject("rocks", cx, cy + 0.25, cz)
placed = true
end
-- Try placing a home
if not placed and #presets.homes > 0 and math.random() < homeDensity then
if isSafeToPlaceHome(worldX, voxelWorldY, worldZ) then
placeObject("homes", cx, cy + 0.5, cz)
placed = true
end
end
end
end
end
end
The issue is that the DeleteTerrain function DOES NOT WORK AT ALL. and i have close to no clue why. any help would be great.
NOTE: you can ignore all the mess and mumbo there just to show the order of how things occur. Im 99.99% sure that everything other then the actual deletion function is the only important thing here
(the first excerpt)