# See if Vector3 is in a Part

What I’m trying to do is generate a random Vector3 in a certain area, which I have done, then check if I can use that Vector3 If it is not in an exclusion zone. I manually created an exclusion zone using BaseParts around objects I want to exclude. My problem is when I supply a point, It will always return the same bool value even if it is or isn’t in any of the exclusion zones.

``````local ExcludedRegion = workspace.ExclusionZoneModel:GetChildren()
local function isInRegion3(region, point)
local v3 = region.CFrame:PointToObjectSpace(point)
return (math.abs(v3.X) <= region.Size.X / 2)
and (math.abs(v3.Y) <= region.Size.Y / 2)
and (math.abs(v3.Z) <= region.Size.Z / 2)
end

local function IsPointInExcludedRegion(Point)
--cycle through all the parts in the exclusion zone and see if the point is in them
for i,Part in pairs(ExcludedRegion) do
if isInRegion3(Part,Point) then
return Point
end
end
return false
end

print(IsPointInExcludedRegion(Vector3.new(0,0,0)))
``````
1 Like

BuildThomas provides a way of going about checking whether a vector3 is in a region.

1 Like

I actually wrote a function for this the other day:

``````function IsPositionInPart(Position,Part) -- Vector3,Instance
local RelPosition = Part.CFrame:PointToObjectSpace(Position)
if math.abs(RelPosition.X) <= Part.Size.X/2 and math.abs(RelPosition.Y) <= Part.Size.Y/2 and math.abs(RelPosition.Z) <= Part.Size.Z/2 then
return true
end
return false
end
``````

This function will check if a Vector3 is within the bounds of a part.

It looks basically identical to your function so I’d see no reason why your solution doesnt work, are you sure nothing is wrong with the physical parts themselves?

3 Likes

this would work for a block part but is there an easy way for it to work with wedges, cylinders, etc?