FillRegion and ExpandToGrid help

Hi, I’m attempting to fill an area with water using FillRegion, here’s my code:

local region = Region3.new(pos1, pos2)
region = region:ExpandToGrid(4)
game.Workspace.Terrain:FillRegion(region, 4, material)

pos1 and pos2 are definitely different positions, as I have tested multiple times. They are also definitely not creating an inverse region as the line with ‘Region3.new’ would have errored in that case, and I have also tried switching these positions to no avail.

The ‘region’ variable created on the very first line is definitely not an empty region, however once ExpandToGrid is used on it it becomes an ‘empty region’ as according to this error and cannot be used for ‘FillRegion’.
image
Line 28 is the ‘FillRegion’ line.

Thanks in advance for any help!

This is quite annoying, but the only way I can get it to work is if pos1’s Coordinates are lower then Pos2’s coordinates.
There probably is a way to do it so Pos2’s coordinates can be smaller I just haven’t figured it out. But when Pos2 coordinates are smaller it gives me the same error.

Ex:
If Pos1 is (0,0,0) and pos2 is (-10, 5, 50), it will error because the x Coordinate in pos2 is smaller then the x coordinate in Pos2.

But this works for me

function fill(material)
	local region = Region3.new(Vector3.new(0,0,0), Vector3.new(10, 5, 10))
	region = region:ExpandToGrid(4)
	game:GetService("Workspace").Terrain:FillRegion(region, 4, material)
end

fill(Enum.Material.Water)

And this gives me the “Region cannot be empty Error”

function fill(material)
	local region = Region3.new(Vector3.new(0,0,0), Vector3.new(-10, 5, 10))
	region = region:ExpandToGrid(4)
	game:GetService("Workspace").Terrain:FillRegion(region, 4, material)
end

fill(Enum.Material.Water)
2 Likes

Ah, I think I see where I’ve gone wrong. Thanks for doing all of this testing, it really helped! Going to move the locations and possibly also switch them.

1 Like

No problem!

1 Like

It worked! Thanks :slight_smile:

1 Like

Alright good!

This is because the first argument is the minimum coordinate, and the second is the maximum. The minimum shouldn’t be larger than the maximum, so it errors. The error is quite vague, though.

Yeah I thought this before and edited it, but forgot that obviously it doesn’t just check the X axis it also checks the Y and Z, therefore the first argument has to be exactly the lower left back coordinate, and the second argument has to be the upper front right coordinate.