How do I script with Region3?

I want to know how this can be done I’ve looked on the wiki, and scripted it before but the problem is I have no knowledge of how big it should be and what any of the properties do. I also have no knowledge of how to exclude all the parts that aren’t humanoids from the region3 so that it only counts player characters.

image
You need to make the Region3 as big as the area you want to check. An Example:

local region = Region3.new(Vector3.new(0, 0, 0), Vector3.new(10, 10, 10))

The script above creates a Region3 that is between 0,0,0 and 10,10,10.
image
Like this ^
To know the parts inside this region you should use: WorldRoot:FindPartsInRegion3
It’s used like this.

local parts = workspace:FindPartsInRegion3(region, part) -- The "part" on the second parameter is used for parts that will be ignored.

To get the humanoids inside a region, I use this method:

local parts = workspace:FindPartsInRegion3(region)
for i, v in pairs(parts) do
     if v:FindFirstChildWhichIsA("Humanoid") then
          print(v.Name .. " has a humanoid.")
     end
end

However, the script above would print every part/model that has a humanoid as a child. To get only players’ characters I use this:

local parts = workspace:FindPartsInRegion3(region)
for i, v in pairs(parts) do
     local IsACharacter = game.Players:GetPlayerFromCharacter(v)
     if IsACharacter ~= nil then
          print(v.Name .. " is a character.")
     end
end

Hope this answers your question, I apologize if it doesn’t.

Note: You don’t need to fill the second parameter of FindPartsInRegion3 for it to work.

1 Like