Region3 not working how I want it to

image
Hello, basically I have some attributes that specify what I need for the region, and nothing is showing up when I run FindPartsInRegion3(region)? Can anyone help me?

local region = Region3.new(playerPlot:GetAttribute("TopLeftFront"),playerPlot:GetAttribute("BottomRightBack"))
local partsInRegion = game.Workspace:FindPartsInRegion3(region)
2 Likes

This method is deprecated. You should be using WorldRoot:GetPartBoundsInBox() instead.


Also, instead of wasting time with getting the corner positions and setting them with attributes, I recommend using this to calculate the corner positons:

local region = Region3.new(BasePart.Position - (BasePart.Size / 2), BasePart.Position + (BasePart.Size / 2))

Here is the documentation on GetPartBoundsInBox() if you need it.
If you still need help, feel free to ask me.

Would this work when there are a bunch of different plots, because there is a different region for every player. ( i mean the way instead of attributes)

Also, how would I use the Region I made in with the GetPartBoundsInBox(), or do I not use it?

Can you explain more on what you mean? I have no idea the inner workings of your game. I don’t know how I am supposed to help.

GetPartBoundsInBox is the replacement method for FindPartsInRegion3. It will do the same thing. FindPartsInRegion3 will not work because it is deprecated.

Basically, I am making a placement system, and I need a region to do this so the player can stack objects.

It errors when I just input the region I created

Are you doing it correctly? It takes three parameters to work. The CFrame, size, and OverlapParams.
It should look something like this

local params = OverlapParams.new()
params.FilterDescendantsInstances = {--[[Add a model or other instance to this table. It will filter through all descendants inside of it.]]}
params.FilterType = Enum.RaycastFilterType.Include --// Enum.RaycastFilterType.Exclude if you don't want the descendants to be included

local parts = workspace:GetPartBoundsInBox(region.CFrame, region.Size, params)

Why not create multiple regions for the players that have their own script with only one specific player assigned to it?

That’s what I am doing, its just that using attributes is the easiest way to do this.

Okay, but it is a pain to change all of the attributes if you move them for whatever reason. I would still recommend using the math I suggested in post #2 to make that part of your life easier. (If you haven’t already applied it.)

How would I make it go very high up? The whole point of this was to make the region extend up the player can stack buildings.

If you’re using a part, then change the part size. The point of the math used in it is to get the two necessary corners to make the Region3.

So just make a part on top of what I want the player to place it on, and make it go up? Would this work?

If you make a part that encompasses the whole area of where you want the player to place stuff, then have a script inside of the part, then you would create the Region3, use RunService.Heartbeat to constantly check the parts inside of the region using GetPartBoundsInBox(), and handle the events and functions necessary in that script.

It would look something similar to this:

local runService = game:GetService("RunService")

local part = script.Parent

local region = Region3.new(part.Position - (part.Size / 2), part.Position + (part.Size / 2))

local function Heartbeat()
	local params = OverlapParams.new()
	params.FilterDescendantsInstances = {--[[Remember to add the model/instance where you want to filter the descendants]]}
	params.FilterType = Enum.RaycastFilterType.Include --// Change this to Enum.RaycastFilterType.Exclude depending on what you want it to do

	local parts = workspace:GetPartBoundsInBox(region.CFrame, region.Size, params)

	--// Make the rest of the code necessary for what you want in here
end

runService.Heartbeat:Connect(Heartbeat)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.