Odd Region3 behavior?

So I’m trying to make a placement system that makes zones, and as it stands it has a huge bug preventing me from moving forward. Some times, the zones turn out like this:


Which incase it isn’t clear, this is the wanted outcome. However most of the time, I get this:

Does anyone know what I’m doing wrong here? My code is below.

				local region = Region3.new(regpoint1, regpoint2)
				local zone = Instance.new("Part")
				zone.Anchored = true
				zone.Size = Vector3.new(region.Size.X, 25, region.Size.Z)
				zone.Parent = workspace
				zone.CFrame = region.CFrame
				zone.CanCollide = false
				zone.Material = Enum.Material.ForceField
				zone.Color = Color3.new(1, 1, 0)

NOTE: regpoint1 and 2 are Vector3 values assigned each time I click the mouse to get the two points for the region3.

Without the rest of the code it’s sorta hard to spot the error.

Can you try scripting a function to place a part at both reg points? Solely for debugging of course, but this will tell us if it’s an issue with your mouse script, or if it’s an issue with the code snippet you posted.

1 Like

Absolutely, here’s a gif illustrating that. (had to pause it so i could select the part to see it’s outline before it cut out)

EDIT: It’s as if it forgets to grab the X and Z values of the two points? Sometimes it does, and other times it doesn’t? I’m not too sure.

1 Like

Looks like it’s really odd Region3 behavior. Above is a video of me running your sample code and simulating it with two parts. When I move one of the parts to behind the other, it acts very strange and creates a thin line.

image

Here’s a screenshot of me running that same code but creating 4 regions, all using the same middle part but in different ‘corners.’

Looks like it only works on specific angles? I’ll look more into Region3 to see if there’s something I’m missing.

Edit: Not angles, but possibly position based.

1 Like

Yeah, please let me know what you find. This is mind boggling and I can’t really find much information on this issue. I found one post describing a similar issue here:

But the solution doesn’t really relate to my current usage of Region3.

EDIT: I slapped the code into a while true loop, and this was the result. It seems that if it goes to a threshold behind the first point it goes flat?

EDIT2: And it also seems that the outcome is completely random, ran it again with no changes and it’s flat at the start

This is what I think is going on:

On the docs site, it’s stated that you can create negative volumetric Region3s. This might not seem to be the case, however, it most likely is. You’re using parts and their sizes to visualize the Region3, and it’s misleading because part sizes can’t go into negatives, making it look like abstract errors.

After finding this out, I searched up some DevForum articles about negative Region3 bounds and found a solution, math.min and math.max!

This new code below, that should work as soon as you copy and paste it over your old code, should fix the errors. It stops the Region3 from becoming negative by only using the maximum and minimum values where it should.

local region = Region3.new(
	Vector3.new(math.min(regpoint1.X, regpoint2.X), math.min(regpoint1.Y, regpoint2.Y), math.min(regpoint1.Z, regpoint2.Z)),
	Vector3.new(math.max(regpoint1.X, regpoint2.X), math.max(regpoint1.Y, regpoint2.Y), math.max(regpoint1.Z, regpoint2.Z))
)

local zone = Instance.new("Part")
zone.Anchored = true
zone.Size = Vector3.new(region.Size.X, 25, region.Size.Z)
zone.Parent = workspace
zone.CFrame = region.CFrame
zone.CanCollide = false
zone.Material = Enum.Material.ForceField
zone.Color = Color3.new(1, 1, 0)

I found the solution here:

1 Like

That seemed to fix it, made about 15 zones with no fail. Thanks a ton for helping me out with this, I wouldn’t have been able to get that solution lol

1 Like