# How can i split a Region3 into many smaller regions to make it work with ReplaceMaterial?

The title really says almost all, i’ve been trying to make a script that easily helps me set up seasonal looks for my game’s map (which uses terrain), and part of that includes replacing all the grass with snow, so i tried using Terrain:ReplaceMaterial(), but i got the “Region is too large” error (the entire size of my map is x4096)), so i thought about splitting the map into smaller regions, so instead of using 1 really big one, i’m now using 16 x1024 ones, and it still gives off the same error, and at this point i feel like i’m going to go insane if i keep trying to manually make smaller and smaller regions, so this is where i ask…:

Does anyone know a way to divide one Region3 into multiple smaller ones?

Here is my code, not really for support directly but to give you a slight idea of the hell i’m in

``````local region1 = Region3.new(Vector3.new(-2048,-88,2048),Vector3.new(-1024,166,1024))

terrain:ReplaceMaterial(region1,4,Enum.Material.Water,Enum.Material.Ice)
terrain:ReplaceMaterial(region1,4,Enum.Material.Grass,Enum.Material.Snow)
terrain:ReplaceMaterial(region1,4,Enum.Material.LeafyGrass,Enum.Material.Snow)

local region2 = Region3.new(Vector3.new(-1024,-88,2048),Vector3.new(0,166,1024))

terrain:ReplaceMaterial(region2,4,Enum.Material.Water,Enum.Material.Ice)
terrain:ReplaceMaterial(region2,4,Enum.Material.Grass,Enum.Material.Snow)
terrain:ReplaceMaterial(region2,4,Enum.Material.LeafyGrass,Enum.Material.Snow)

local region3 = Region3.new(Vector3.new(0,-88,2048),Vector3.new(1024,166,1024))

terrain:ReplaceMaterial(region3,4,Enum.Material.Water,Enum.Material.Ice)
terrain:ReplaceMaterial(region3,4,Enum.Material.Grass,Enum.Material.Snow)
terrain:ReplaceMaterial(region3,4,Enum.Material.LeafyGrass,Enum.Material.Snow)

local region4 = Region3.new(Vector3.new(1024,-88, 2048),Vector3.new(1024,166,2048))

terrain:ReplaceMaterial(region4,4,Enum.Material.Water,Enum.Material.Ice)
terrain:ReplaceMaterial(region4,4,Enum.Material.Grass,Enum.Material.Snow)
terrain:ReplaceMaterial(region4,4,Enum.Material.LeafyGrass,Enum.Material.Snow)

local region5 = Region3.new(Vector3.new(-2048,-88,1024),Vector3.new(-1024,166,0))

terrain:ReplaceMaterial(region5,4,Enum.Material.Water,Enum.Material.Ice)
terrain:ReplaceMaterial(region5,4,Enum.Material.Grass,Enum.Material.Snow)
terrain:ReplaceMaterial(region5,4,Enum.Material.LeafyGrass,Enum.Material.Snow)

local region6 = Region3.new(Vector3.new(-1024,-88,1024),Vector3.new(0,166,0))

terrain:ReplaceMaterial(region6,4,Enum.Material.Water,Enum.Material.Ice)
terrain:ReplaceMaterial(region6,4,Enum.Material.Grass,Enum.Material.Snow)
terrain:ReplaceMaterial(region6,4,Enum.Material.LeafyGrass,Enum.Material.Snow)

local region7 = Region3.new(Vector3.new(0,-88,1024),Vector3.new(1024,166,0))

terrain:ReplaceMaterial(region7,4,Enum.Material.Water,Enum.Material.Ice)
terrain:ReplaceMaterial(region7,4,Enum.Material.Grass,Enum.Material.Snow)
terrain:ReplaceMaterial(region7,4,Enum.Material.LeafyGrass,Enum.Material.Snow)

local region8 = Region3.new(Vector3.new(1024,-88, 1024),Vector3.new(2048,166,0))

terrain:ReplaceMaterial(region8,4,Enum.Material.Water,Enum.Material.Ice)
terrain:ReplaceMaterial(region8,4,Enum.Material.Grass,Enum.Material.Snow)
terrain:ReplaceMaterial(region8,4,Enum.Material.LeafyGrass,Enum.Material.Snow)

local region9 = Region3.new(Vector3.new(-2048,-88,0),Vector3.new(-1024,166,-1024))

terrain:ReplaceMaterial(region1,4,Enum.Material.Water,Enum.Material.Ice)
terrain:ReplaceMaterial(region1,4,Enum.Material.Grass,Enum.Material.Snow)
terrain:ReplaceMaterial(region1,4,Enum.Material.LeafyGrass,Enum.Material.Snow)

local region10 = Region3.new(Vector3.new(-1024,-88,0),Vector3.new(0,166,-1024))

terrain:ReplaceMaterial(region2,4,Enum.Material.Water,Enum.Material.Ice)
terrain:ReplaceMaterial(region2,4,Enum.Material.Grass,Enum.Material.Snow)
terrain:ReplaceMaterial(region2,4,Enum.Material.LeafyGrass,Enum.Material.Snow)

local region11 = Region3.new(Vector3.new(0,-88,0),Vector3.new(1024,166,-1024))

terrain:ReplaceMaterial(region3,4,Enum.Material.Water,Enum.Material.Ice)
terrain:ReplaceMaterial(region3,4,Enum.Material.Grass,Enum.Material.Snow)
terrain:ReplaceMaterial(region3,4,Enum.Material.LeafyGrass,Enum.Material.Snow)

local region12 = Region3.new(Vector3.new(1024,-88, 0),Vector3.new(2048,166,-1024))

terrain:ReplaceMaterial(region4,4,Enum.Material.Water,Enum.Material.Ice)
terrain:ReplaceMaterial(region4,4,Enum.Material.Grass,Enum.Material.Snow)
terrain:ReplaceMaterial(region4,4,Enum.Material.LeafyGrass,Enum.Material.Snow)

local region13 = Region3.new(Vector3.new(-2048,-88,-1024),Vector3.new(-1024,166,-2048))

terrain:ReplaceMaterial(region5,4,Enum.Material.Water,Enum.Material.Ice)
terrain:ReplaceMaterial(region5,4,Enum.Material.Grass,Enum.Material.Snow)
terrain:ReplaceMaterial(region5,4,Enum.Material.LeafyGrass,Enum.Material.Snow)

local region14 = Region3.new(Vector3.new(-1024,-88,-1024),Vector3.new(0,166,-2048))

terrain:ReplaceMaterial(region6,4,Enum.Material.Water,Enum.Material.Ice)
terrain:ReplaceMaterial(region6,4,Enum.Material.Grass,Enum.Material.Snow)
terrain:ReplaceMaterial(region6,4,Enum.Material.LeafyGrass,Enum.Material.Snow)

local region15 = Region3.new(Vector3.new(0,-88,-1024),Vector3.new(1024,166,-2048))

terrain:ReplaceMaterial(region7,4,Enum.Material.Water,Enum.Material.Ice)
terrain:ReplaceMaterial(region7,4,Enum.Material.Grass,Enum.Material.Snow)
terrain:ReplaceMaterial(region7,4,Enum.Material.LeafyGrass,Enum.Material.Snow)

local region16 = Region3.new(Vector3.new(1024,-88, -1024),Vector3.new(2048,166,-2048))

terrain:ReplaceMaterial(region8,4,Enum.Material.Water,Enum.Material.Ice)
terrain:ReplaceMaterial(region8,4,Enum.Material.Grass,Enum.Material.Snow)
terrain:ReplaceMaterial(region8,4,Enum.Material.LeafyGrass,Enum.Material.Snow)
``````

I don’t really know what else to say, i’m just stuck…

Here is a code that should split it into smaller parts:

``````local min = Vector3.new(-10, -10, -10)
local max = Vector3.new(10, 10, 10)
-- The imaginary block extendes from Min to Max

local subdivisions = 5 -- How many subdivisions it should have

local dx = (max.X - min.X)/subdivisions
local dy = (max.Y - min.Y)/subdivisions
local dz = (max.Z - min.Z)/subdivisions

for x = min.X, max.X - dx, dx do
for y = min.Y, max.Y - dy, dy do
for z = min.Z, max.Z - dz, dz do
local region = Region3.new(Vector3.new(x, y, z) , Vector3.new(x, y, z) + Vector3.new(dz, dx, dy))

-- Do whatever with the region

end
end
end
``````

I am not certain if I got the maths right, but hopefully I did.
Edit: Inform me in case I got the maths wrong, I have an alternative solution in mind.

1 Like

They likely are wrong, when looking at it, while it did in fact work, i wouldn’t exactly say it worked right

Excuse the phone camera picture, im not logged into the devforum on this computer, the grass is already painted white, note the stripes of snow and ice on the water