Region3 Issues dnt

Hello! I would like to know how I can use it, what it is for and how to create region3, I would really appreciate it if someone would give me a hand with that. :frowning:

1. local r = Region3.new(Vector3.new(2, 3, 4), Vector3.new(8, 6, 5))
2. print(r) --> 5, 4.5, 4.5, 1, 0, 0, 0, 1, 0, 0, 0, 1; 6, 3, 1
3. print(r.CFrame == CFrame.new(5, 4.5, 4.5))
4. print(r.Size == Vector3.new(6, 3, 1))

Try Looking at this thread
Region3 tutorial (Easy Difficulty)

1 Like

So supposedly, Region3 can take place in a form of a specific region you want to capture inside the workspace itself

For the example that was shown, I believe it takes 2 Vector3 values & converts it into a Region (Or a square radius for more simplistic terms), and you can get the center of where that Region is exactly (Keep in mind though, that your Region3 example is relative to the world origin)

The most common use for Region3 is detecting if something is in a specific Region, which can be useful for checking square boundaries (Of course we have Magnitude as well, but that’s implemented as a radius implemented as a circle)

Say we wanted to detect if a object was in a specific Region, well we’d first need to get our Sizes so we can compare what the medium between the 2 can be:

local RegionPart = workspace.Part
local MinSize = RegionPart.Position - (0.5 * RegionPart.Size) 
local MaxSize = RegionPart.Position + (0.5 * RegionPart.Size)

local Region = Region3.new(MinSize, MaxSize)

Creating a Region3 requires a “MinSize”, and “MaxSize” then I believe it divides & takes the medium of both those Sizes

After we have our Region we created, we can then put it through a while true do loop so that it’ll check frequently for nearby parts/objects:

while true do
    local Parts = workspace:FindPartsInRegion3(Region, RegionPart, nil)
    wait(1)
end

FindPartsInRegion3 would return back an Array (Or table which would be this: {}), and it has 3 parameters:

  1. The Region we just created

  2. The part (And it’s descendants) that we want to ignore when we check for the Region

  3. A max counter for the amount of parts we want to detect in that Region (Setting it to nil would be infinite I believe)

After we have our Parts, we can loop through our table & check if a Random Object is inside the Region at all:

--Inside our loop
for _, Part in pairs(Parts) do
    if Part.Name == "GreenPart" then
        print("This Green Part is inside the Region!")
    end
end

Of course, if we’d wanna get a Player we can check using the GetPlayerFromCharacter function & referencing the Part’s Parent

But yeah that’s the basis of that Region3 can do! Kinda think of it as like taking a chunk of the world & detecting that “chunk” for parts that could be inside

local RegionPart = workspace.Part
local MinSize = RegionPart.Position - (0.5 * RegionPart.Size) 
local MaxSize = RegionPart.Position + (0.5 * RegionPart.Size)

local Region = Region3.new(MinSize, MaxSize)

while true do
    local Parts = workspace:FindPartsInRegion3(Region, RegionPart, nil)

    for _, Part in pairs(Parts) do
        if Part.Name == "GreenPart" then
            print("This Green Part is inside the Region!")
        end
    end
    wait(1)
end
1 Like

Wow! This is very easy to understand, thank you very much I really appreciate your time in writing this code, thank you! :smiley:

2 Likes