I tried this:
local point1 = workspace.Point1.Position
local point2 = workspace.Point2.Position
local region = Region3.new(point1, point2)
but whenever I try to scan for any parts inside the 2 points I get nothing at all.
I tried this:
local point1 = workspace.Point1.Position
local point2 = workspace.Point2.Position
local region = Region3.new(point1, point2)
but whenever I try to scan for any parts inside the 2 points I get nothing at all.
Take a look at Region3 on the DevHub.
It states:
the order of the provided bounds matters: by switching them, the polarity of the Size components will switch. It is possible to create a Region3 with a negative volume.
https://developer.roblox.com/en-us/api-reference/datatype/Region3
Reverse the region3 (Region3.new(point2, point1))
to see if anything changes.
Reversing the 2 points didn’t fix anything it still doesn’t work.
local whitelist = {}
local regions = {}
local model = workspace:WaitForChild("Regions")
for _,part in pairs(model:GetChildren()) do
local areaName = part.Name
local point1 = part:FindFirstChild("Point1")
local point2 = part:FindFirstChild("Point2")
local reg = Region3.new(point2.Position, point1.Position)
regions[areaName] = {region = reg}
end
Hey. Could you provide the code you’re using to “scan”?
Yeah sure this is the scan code;
while wait() do
for name,test in pairs(regions) do
local region = test.region
local parts = workspace:FindPartsInRegion3(region)
if parts then
for _,v in pairs(parts) do
print(v)
end
end
end
end
Is it possible you have a value in one of the positions that is larger than the same axis in the other position while its other coordinate values are smaller? Small inconsistencies might cause something like this unexpected, basically just compare the coordinates of both positions to make sure that all coordinates of one position is larger/smaller than the other.
Btw, I believe the FindPartsInRegion3 gives an empty table if you don’t get any parts so you can skip the if statement checking if a result was found.
I’m confused of what you mean by comparing the coordinates to see if one of them is larger? The coordinates are just points, the point1, and point2 bricks are the same size property.
These are the 2 bricks I use to determine if a player is inside of the combined points.
The 2 points would create a box, but it’s not visible because it’s not a part, but anyways anyone that walks into that box would be detected.
Position X < Position2 X and same for Y and Z. Basically compare those to make sure that it results in XYZ having the same conditional output (true/false)
If you compare X vs the other X by >, then Y and Z should also compare by >. If X is larger than the other X, then Y and Z should be as well for the other position’s Y and Z.
Seems your Z value is the one causing inconsistency, it is larger than the second position Z value while the other XY values are smaller than their second position XY values.
You could use this to test for the Region3 inconsistencies:
local function compare(pos, pos2)
local x,y,z = pos.X, pos.Y, pos.Z
local x2, y2, z2 = pos2.X, pos2.Y, pos2.Z
return (x > x2 and y > y2 and z > z2) or (x < x2 and y < y2 and z < z2)
end
print( compare( ) ) -- put position values here (vector3)
Attempt:
for _,part in pairs(model:GetChildren()) do
local areaName = part.Name
local point1 = part:FindFirstChild("Point1")
local point2 = part:FindFirstChild("Point2")
local reg = Region3.new(point2.Position, point1.Position)
regions[areaName] = {region = reg}
local function compare(pos, pos2)
local x,y,z = pos.X, pos.Y, pos.Z
local x2, y2, z2 = pos2.X, pos2.Y, pos2.Z
return (x > x2 and y > y2 and z > z2) or (x < x2 and y < y2 and z < z2)
end
print(compare(point1.Position, point2.Position))
end
Result:
If it’s false that means there’s inconsistencies right? And if so how can I fix this?
Well this means as I said earlier you have an inconsistent coordinate value that is causing your unexpected Region3 result. You should adjust your Z value to see if you can fix this difference.
I believe that the Region3 created also has a CFrame and Size property you could index to recreate what the Region3 looks like with a part for debug. (e.g. yourRegion3.CFrame
)
Here’s what happened when I created a part and made it the cframe and size of the region:
Script:
for _,part in pairs(model:GetChildren()) do
local areaName = part.Name
local point1 = part:FindFirstChild("Point1")
local point2 = part:FindFirstChild("Point2")
local reg = Region3.new(point2.Position, point1.Position)
regions[areaName] = {region = reg}
local part = Instance.new("Part", workspace)
part.Transparency = .5
part.BrickColor = BrickColor.new("Really red")
part.Anchored = true
part.CanCollide = false
part.CFrame = reg.CFrame
part.Size = reg.Size
end
Just focus on fixing it before debugging. You only have to fix the Z value.
Well I tried changing the Z Value to negative but that made the line a dot instead. So I don’t think the Z coordinate is the problem, it could be the two other coordinate values need to be negative.
Editing the coordinates X and Y and making them negative created this which should be what the region is. So I think I need to make X and Y on the region negative instead of what it already is.
That works as well since it makes XY the same condition as Z against the other position’s XYZ values. Is that your solution?
Not sure yet, all I did was reverse the X and Y coordinates for the size of a Part, but this is region3 meaning I have to reverse the coordinates of the position. I think I may know how to do that though.
Reversing the 2 point coordinates X, and Y didn’t solve my problem. So I’m not sure what the problem is yet.