Well as I don’t really like multiple raycasting method, I do this kind of stuffs like this,
1, Get 8 Positions of a part’s corners.
So for this, you can use this script.
local Vertices = {
{1, 1, -1}, --v1 - top front right
{1, -1, -1}, --v2 - bottom front right
{-1, -1, -1},--v3 - bottom front left
{-1, 1, -1}, --v4 - top front left
{1, 1, 1}, --v5 - top back right
{1, -1, 1}, --v6 - bottom back right
{-1, -1, 1},--v7 - bottom back left
{-1, 1, 1} --v8 - top back left
}
for _, Vector in pairs(Vertices) do
local CornerPos = (Part.CFrame * CFrame.new(Size .X/2 * Vector[1], Size .Y/2 * Vector[2], Size .Z/2 * Vector[3])).Position
end
2, Check if all 8 vectors are in the specific area. (Or more than 1 vector)
And for this, you acn use this one.
function isInsideBrick(position, brick)
local v3 = brick.CFrame:PointToObjectSpace(position)
return (math.abs(v3.X) <= brick.Size.X / 2)
and (math.abs(v3.Y) <= brick.Size.Y / 2)
and (math.abs(v3.Z) <= brick.Size.Z / 2)
end
So you can combine those 2 scripts properly to check a part is in an area without multiple raycasting or region3 thing.