# How would I make a for loop fill in every part in between these 2 on a 4x4 grid

I’d like to fill in the space between these blocks in a 4x4 grid.

Here’s what I have for the logic and it works if it’s aligned along X and Y

``````r.SetCells = --https://robloxapi.github.io/ref/class/Terrain.html#member-SetCells
function(region,material,block,ore)
local rX = region.Min.X
local rY = region.Min.Y
local rZ = region.Min.Z
local dist = (region.Min.X - region.Max.X)
local dist2 = (region.Min.Y - region.Max.Y)
local dist3 = (region.Min.X - region.Max.X)

dist = dist / 4
dist2 = dist2/4
dist3 = dist3/4
local absdist = math.abs(dist)
local absdist2 = math.abs(dist2)
local absdist3 =  math.abs(dist3)

local stdrpos = region.Max

--c.PlaceTerrainBlock:Fire("MegaGrass",region.Min)
for o = 0, absdist2 do
if o == absdist2+1 then return else
for i = 0, absdist do
if absdist2 == dist2 then
if i == absdist+1 then return else
if absdist == dist then
print("XY2")
local pos = Vector3.new(region.Max.X + i*4, region.Max.Y + o*4, region.Max.Z)
c.PlaceTerrainBlock:Fire("MegaGrass",pos)
else
print("XY2e")
local pos = Vector3.new(stdrpos.X - i*4, stdrpos.Y + o*4, stdrpos.Z)
c.PlaceTerrainBlock:Fire("MegaGrass",pos)
end
end
elseif absdist == dist then
if i == absdist+1 then return else
if absdist == dist then
print("XY1")
local pos =  Vector3.new(stdrpos.X + i*4, stdrpos.Y - o*4, stdrpos.Z)
c.PlaceTerrainBlock:Fire("MegaGrass",pos)
else
print("XYe")
local pos =  Vector3.new(stdrpos.X - i*4, stdrpos.Y - o*4, stdrpos.Z)
c.PlaceTerrainBlock:Fire("MegaGrass",pos)
end
end
end
end
end
end
end
``````

This works for what I need to do and it’s pretty fast if you don’t use my placeterrainblock thing.

``````r.SetCells = --https://robloxapi.github.io/ref/class/Terrain.html#member-SetCells
function(region,material,block,ore)
local rX = region.Min.X
local rY = region.Min.Y
local rZ = region.Min.Z
local dist = (region.Min.X - region.Max.X)
local dist2 = (region.Min.Y - region.Max.Y)
local dist3 = (region.Min.Z - region.Max.Z)

dist = dist / 4
dist2 = dist2/4
dist3 = dist3/4
local absdist = math.abs(dist)
local absdist2 = math.abs(dist2)
local absdist3 =  math.abs(dist3)

local stdrpos = region.Min
print("Regions ",region.Min,region.Max)
print("ABSDIST ",absdist,absdist2,absdist3)
print("DIST ", dist,dist2,dist3)
local pos = Vector3int16.new()
--c.PlaceTerrainBlock:Fire("MegaGrass",region.Min)
for x = 0,absdist do
for y = 0,absdist2 do
for z = 0,absdist3 do
if absdist == dist then
pos = Vector3.new(GridPos(stdrpos.X - x*4),GridPos(stdrpos.Y+y*4),GridPos(stdrpos.Z))
else
pos = Vector3.new(GridPos(stdrpos.X + x*4),GridPos(stdrpos.Y+y*4),GridPos(stdrpos.Z))
end
if absdist3 == dist3 then
pos = Vector3int16.new(pos.X,pos.Y,GridPos(stdrpos.Z - z*4))
else pos = Vector3int16.new(pos.X,pos.Y,GridPos(stdrpos.Z + z*4))
end
wait(0)
c.PlaceTerrainBlock:Fire("MegaGrass",pos)
end
end
end
end`````````

video of it in action: