So, I was tinkering around with chunk generation scripts found in the toolbox… and the result is that it does generate infinitely, but not in a gridlike manner. I do believe the first function “generateChunk” may do what I want, but I’m not sure how to manipulate it properly
math.randomseed(tick()/10)
local rows = 1
local columns = 1
print(rows,columns)
local chunksizeX = 20
local chunksizeZ = 20
function GenerateChunk(position)
local chunk = chunks:GetChildren()[math.random(1,#chunks:GetChildren())]:Clone()
chunk.Parent = workspace.Map.Generated
chunk:SetPrimaryPartCFrame( CFrame.new(position))
end
function Generate(x,y,z)
for i = 1,columns,1 do
for i = 1,rows,1 do
x=x+chunksizeX
GenerateChunk(Vector3.new(x,y,z))
end
z=z+chunksizeZ
x=0
end
end
while true do
for _,i in pairs(game.Players:GetPlayers()) do
if i.Character ~= nil and i.Character:FindFirstChild("Head") then
print("Generated Terrain for player " .. i.Name)
GenerateChunk(Vector3.new(i.Character:FindFirstChild("Head").Position.X,1,i.Character:FindFirstChild("Head").Position.Z))
end
end
game["Run Service"].Heartbeat:Wait()
end```
So, by what I am looking you want to use the “Generate” function. It seems like you give it a starting position. However, this position depends on the rows and columns. If you make something like “5” and “5” (25 in total) then it will generate in a grid.
A question, why are you looping with “while”? I believe the offset is happening because you are generating the chunks every iteration. This means that when you move your player’s head it will move the chunks.
Another thing. Try to make a grid system instead of the actual position. This is what I mean:
You can see how there are 2 grids overlaying. One is player blue and the other one is red. What you want to do is make it so both of them use the same grid position (I guess you want to do that).
Imagine the purple dots are the center of each cell. You want to make so the chunks start generating the closest to the player using that purple dot. This will ensure that for those 2 players they generate in the same axis.