Parts generate automatically?

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.

1 Like

What solutions have you tried so far?

You forgot to answer this question.

1 Like

I guess what you are trying to achieve is Chunks system take a look at this

1 Like

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
1 Like

Where do I put the script?

Why do I need a folder?

1 Like

ServerScript inside ServerScriptService

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.

1 Like

It works but it generates a load of them, it might be because the size of the part is

block.Size = Vector3.new(2048,4,2048)
1 Like