Procedural generation error, script leaves doesn't fill in specific 3 tiles

My generator works but leaves 3 tiles (36x36 space) out once close to the spawn, it’s always the same shape and position. The shape has an “<” shape. The issue is that players can fall trough those spots out the map and it looks unprofessional. I used (procedural generation)
There arn’t any error messages.

Here is my code btw:

local RegularTilesFolder = serverStorage.Level_0.RugularZone
local spawnTile = serverStorage.Level_0.SpawnTile

firstTile = spawnTile:Clone()
firstTile.Parent = game.Workspace.Level_0
firstTile:MoveTo(Vector3.new(0,-100,0))

function create(v)
	local newTile
	if v.TileToPlace.Value == nil then
		newTile = RegularTilesFolder:GetChildren()[math.random(1,#RegularTilesFolder:GetChildren())]:Clone()
	else
		newTile = RegularTilesFolder:GetChildren()[v.TileToPlace.Value]
	end
	newTile.Parent = game.Workspace.Level_0
	newTile:PivotTo(CFrame.new(v.Position) * CFrame.fromOrientation(math.rad(v.Orientation.X), math.rad(v.Orientation.Y), math.rad(v.Orientation.Z)))
	return newTile
end

local newTiles = {}

function generate(PreviousTile: Model)
	for i,v in pairs(PreviousTile:GetChildren()) do
		if v:IsA("BasePart") and v.Name == "NewTileStart" then
			local newTile = create(v)
			local GetPartsInPart = game.Workspace:GetPartsInPart(newTile.Collision)
			if #GetPartsInPart > 1 then
				newTile:Destroy()
			else
				table.insert(newTiles,newTile)
			end
		end
	end
	wait(0)
	for i,v in pairs(PreviousTile:GetChildren()) do
		if v:IsA("BasePart") and v.Name == "NewTileStart" then
			v:Destroy()
		end
	end
	table.remove(newTiles,table.find(newTiles,PreviousTile))
	for i,v in pairs(newTiles) do
		generate(v)
	end
end

generate(firstTile)

pls format the code properly by putting three bacticks (`) before and after the code

also cant help u rn sorry

1 Like

Its okay, thanks for the tip btw

Schermafbeelding 2025-04-09 162626
that’s how it looks like

found the bug, I needed to add the first tile to the new tiles table before calling the gererate function the first time

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.