I have this function that get an Object from the workspace and an integer value:
function GetLocalParts(Object, Range) ObjectPosition = Object:GetPrimaryPartCFrame() -- Region = ? for i, v in pairs(game.Workspace:FindPartsInRegion3(Region, nil, 100)) print(Parts[i].Name) end end
What the function is supposed to do is create a Region3 with the radius as the Range
value, but I have never worked with regions before and the wiki is not helping to understand.
Once it has created the Region, it will print all of the parts within it. How do I create the region?
So a Region3 won't work perfectly with a "radius" because that would create a sphere and a Region3 is a 3D rectangular prism.
A Region3 is constructed with two vector3s to define one corner, and the other corner.
To create a "radius" like prism around an object, you will want to create corners above behind and to the left of the object and a corner below, in front of, and to the right of the object. Here's how I would do it. The way that this box is created, the coordinates of the points have to be smaller first, then large.
For example we create a box with corners (1,1,1) to (9,9,9). All points from (1,9,9) to (9,1,9) are contained in our box.
local object corner1 = object.Position - Vector3.new(range, range, range) corner2 = object.Positon + Vector3.new(range, range, range) -- Luckily because of how the math works out, the coordinate of corner 1 are always lower. local region = Region3.new(corner1, corner2)