What I am attempting to achieve
What I am currently trying to achieve is to ensure a part is completely within the grid boundaries. If it’s not in bounds, it will change the hitbox color to red.
The issue
The main issue is, I cannot find an efficient way to get it to work properly and EFFICIENTLY
Solutions I’ve Tried
The main solution I tried was to have a giant transparent part covering the entire grid (known as the region part). When the player clicks on a part to start placement, the region part decreases it’s size with the x and y axis as well as creating a region with Region3, which is the same size and position as the region part. Then, every heartbeat, the script will check if all parts of the model is inside the region. Now if the user doesn’t choose to rotate the model, it works. However, if they do, it causes issues. I’ve tried many other solutions, yet none of them seems to work.
Essentially, I just need help getting it fixed up or if there’s a better and more efficient method for such.
https://gyazo.com/60e7fd4d262298f9d5b1605212e80e0b
UPDATE: Here’s some snippits of the script.
Here, this is part of the function that is called as soon as placement initiates.
RegionArea.Size = RegionArea.Size - Vector3.new(ObjectPlacing.Hitbox.Size.X * 2 - HitboxSizeOffset, 0, ObjectPlacing.Hitbox.Size.Z * 2 - HitboxSizeOffset)
Region = Region3.new(RegionArea.Position - (RegionArea.Size/2), RegionArea.Position + (RegionArea.Size/2))
And this is the boundary check ran every heartbeat.
local RegionParts = workspace:FindPartsInRegion3WithWhiteList(Region, ObjectPlacing:GetDescendants(), math.huge)
local Parts = {}
for _, v in pairs(ObjectPlacing:GetDescendants()) do
if v:IsA("BasePart") then
table.insert(Parts, v)
end
end
if #Parts == #RegionParts then
CanPlace = true
else
CanPlace = false
return BrickColor.new("Really red")
end