How do I change the position of a Region3?

I am confused on how to fix this. How do I change the position of a Region3? I tried using CFrame to move the region, but it didn’t work.

15:16:14.287 - CFrame cannot be assigned to
^ on line 5

local Point2 = Vector3.new(0.84,3.1,78.862)
local Region = Region3.new(Point1, Point2)
local res = 4

Region.CFrame = CFrame.new(0.84,3.1,68.862)
Region = Region:ExpandToGrid(res)

for _,Part in pairs(game.Workspace:FindPartsInRegion3(Region,nil,math.huge)) do
  print(Part.Name)
end```
2 Likes

Your region is determined by two points in the workspace using vector3. You can change the position of a region3 by changing the two points respectively. I.e having two parts then a center part then making it a model and setting the models PrimaryPartCFrame.

1 Like

Oh, okay. How would you exactly change the size of it?

Say you have these two parts, top one part 1, top one part 2.

If you plug their positions into a region3 getting the math.min and math.max of both part’s X,Y,Z on a vector3 position. Your region3 will be approximately that box.

Oh! So you would get the position of part0 and part1, then make a Region3 with it. Do you need to convert anything, though? (for example, CFrame.Angles(0,math.rad(90),0))

You can’t use CFrame in Region3, Region3 is strictly Vector3.

Oh, okay. How do you use math.min and math.max? Do you possibly have a demonstration?

So math.min and math.max work in the same fashion with different returnvalues. math.min, you input two number values and it returns the smallest one. So in my case of an out of bounds script for a hockey game.

Vector3.new(math.min(workspace.OOP1.Position.X,workspace.OOP2.Position.X),math.min(workspace.OOP1.Position.Y,workspace.OOP2.Position.Y),math.min(workspace.OOP1.Position.Z,workspace.OOP2.Position.Z))

which makes a vector3 of the smallest positions based on two parts “OOP1” and “OOP2” which are two points which make the “Out of play” box. math.max is the same, but it returns the highest value.

Makes sense. Do you need a return statement for math.min/math.max or is it already built in and how would you get that number?

You define it. If you want the actual output from the function you would do:

local maxval = math.max(0,100)

and maxval would be 100.

Can this work?

local Point1 = Vector3.new(math.min(RegionFolder.Part.Position.X,RegionFolder.Part2.Position.X),math.min(RegionFolder.Part.Position.Y,RegionFolder.Part2.Position.Y),math.min(RegionFolder.Part.Position.Z,RegionFolder.Part2.Position.Z))

(point2 having math.max) and regionfolder already being a variable

Yeah, that works, it’s how I made my Out of play script.

Okay, thanks for your contribution and help.

1 Like