So I basically have the whole thing made but I run into a slight problem, if the Items Hit box is equal size in X and Z, I don't run into this problem but if one Side is bigger than the other, the longer side will hang of the edge of the grid, any help would be appreciated
--localscript
function Collision(ItemClone)
local Platform = game.Workspace.Platforms:WaitForChild(Player.Name.. "'s Facility", 100).Base["Base Tier 1"]
local Visual = ItemClone
if Visual:FindFirstChild("HitBox") then
local Hitbox = Visual.HitBox
local TycoonBase = Platform
local TycoonBaseSizeX, TycoonBaseSizeZ
local HitboxSizeX, HitboxSizeZ
TycoonBaseSizeX, TycoonBaseSizeZ = TycoonBase.Size.x, TycoonBase.Size.z
HitboxSizeX, HitboxSizeZ = Hitbox.Size.x, Hitbox.Size.z
local TycoonTopLeft = TycoonBase.CFrame * CFrame.new(Vector3.new(TycoonBase.Size.x/2, 0, TycoonBase.Size.z/2))
local BaseAngleX, BaseAngleY, BaseAngleZ = CFrame.new(TycoonBase.Position, (TycoonBase.CFrame*Vector3.new(1, 0, 0))):toEulerAnglesXYZ()
local VectorRotation = CFrame.Angles(BaseAngleX, BaseAngleY, BaseAngleZ)
--- Get Platform Region ---
local BasePosition = Platform.Position
local BaseSizeOffset = Platform.Size/2
local BasePoint1 = Platform.Position - BaseSizeOffset
local BasePoint2 = Platform.Position + BaseSizeOffset
local BaseRegion = Region3.new(BasePoint1, BasePoint2)
local XPos, ZPos = Mouse.Hit.p.X, Mouse.Hit.p.Z
XPos = math.floor(XPos/2.5 + 0.5)*2.5
XPos = math.min(XPos, (BaseRegion.CFrame.p.X + BaseSizeOffset.X)-(HitboxSizeZ/2))
XPos = math.max((BaseRegion.CFrame.p.X - BaseSizeOffset.X)+(HitboxSizeZ/2), XPos)
ZPos = math.floor(ZPos/2.5 + 0.5)*2.5
ZPos = math.min(ZPos, (BasePosition.Z + BaseSizeOffset.Z)-(HitboxSizeZ/2))
ZPos = math.max((BasePosition.Z - BaseSizeOffset.Z)+(HitboxSizeZ/2), ZPos)
-- 2.5 == Pillar
local HitboxSize = Hitbox.Size
local YPos = (BasePosition.Y + BaseSizeOffset.Y)+(HitboxSize.Y/2)
if Rotate then
YRotate = YRotate + 90
Rotate = false
end
local NewVector = CFrame.new(XPos, YPos, ZPos) * CFrame.fromEulerAnglesXYZ(0, math.rad(YRotate), 0)
local RegionVectorMin = NewVector * CFrame.new(Vector3.new(HitboxSizeX/2, -Hitbox.Size.y/2, HitboxSizeZ/2))
local RegionVectorMax = NewVector * CFrame.new(-Vector3.new(HitboxSizeX/2, -Hitbox.Size.y/2, HitboxSizeZ/2))
local Hitboxes = game.Workspace:FindPartsInRegion3(
Region3.new(
Vector3.new(
math.min(RegionVectorMin.x, RegionVectorMax.x),
math.min(RegionVectorMin.y, RegionVectorMax.y),
math.min(RegionVectorMin.z, RegionVectorMax.z)
) + Vector3.new(0.1, 0, 0.1),
Vector3.new(
math.max(RegionVectorMin.x, RegionVectorMax.x),
math.max(RegionVectorMin.y, RegionVectorMax.y),
math.max(RegionVectorMin.z, RegionVectorMax.z)
) - Vector3.new(0.1, 0, 0.1)
), nil, math.huge
)
local ModelColliding = false
for i, Hitbox in pairs(Hitboxes) do
--- Repeated Variables ---
local Block_Place = Hitbox.Name == "HitBox"
local Not_Desc_Of = not Hitbox:IsDescendantOf(Visual)
if Block_Place and Not_Desc_Of then
ModelColliding = true
Highlight.Color3 = Color3.new(1, 0, 0)
Highlight.SurfaceColor3 = Color3.new(1, 0, 0)
Placeable = false
end
end
if not ModelColliding then
Highlight.Color3 = Color3.new(0, 1, 0)
Highlight.SurfaceColor3 = Color3.new(0, 1, 0)
Placeable = true
end
LastPosition = NewVector
Visual:SetPrimaryPartCFrame(Visual.PrimaryPart.CFrame:lerp(LastPosition, .2))
end
end

3 comments
Does rotation affect what happens?
Rotation doesn't effect much, the short side will be the side sticking off where the large side is against the edge
I added 2 images of what i mean in the post