I want parts to generate as the player goes further and disappear if the player is a certain amount of studs away from that part. It’s like infinitely generating terrain but with parts.
The issue is I have no clue how to do this. I have also found nothing on how to do this.
To generate the terrain, you can simply use 2 for loops.
local size = Vector2.new(10,10)
for x = 0, size.X do
for y = 0, size.Y do
local block = Instane.new("Part")
block.Anchored = true
block.Position = Vector3.new(x * 4,0,y * 4)
block.Size = Vector3.new(4,4,4)
block.Parent = workspace.Generated
end
end
And to unrender them, you can use a seperate folder in ReplicatedStorage or anywhere.
local renderdist = 50
for _, block:BasePart in workspace.Generated:GetChildren() do
if (rootPart.Position - block.Position) > renderdist then
block.Parent = Storage.Unrendered
end
end
for _, block in Storage.Unrendered:GetChildren() do
if (rootPart.Position - block.Position) < renderdist then
block.Parent = workspace.Generated
end
end
To store the blocks that are unrendered, if you just remove a block, how will you get it back? (Unless you still have a variable of it.)
Edit : I said put the folder in ReplicatedStorage because when a part is in ReplicatedStorage, it’s not visible on your screen. Also, that isn’t the full script of course. You probably need 1 ServerScript and 1 LocalScript.