So this system for detecting objects in bounds of the plot works for the ones that are not rotated, like walls. However when it comes to roofs for example, that are rotated walls likely, they are able to go to the half out of the plot and that also affects my grid of 0.5 for not touching the walls and connecting with them. I already tried making that code for fixing it but wasnt sucesful.
local function bounds(c : CFrame, cx : number, cz : number, plt : Instance) : CFrame
local pos = plot.CFrame
local xBound = (plot.Size.X*0.5) - cx
local zBound = (plot.Size.Z*0.5) - cz
local newX = clamp(c.X, -xBound, xBound)
local newZ = clamp(c.Z, -zBound, zBound)
local newCFrame = cframe(newX, 0, newZ)
return newCFrame
end
If someone is able to give me a light on that it would be so much appreciated.