Calculating y-offset semi-works for placement system

This is what happens when i place stuff


My current script

Position is from raycasting the mouse position

local CF, Size = ClientStructure:GetBoundingBox()

local NewAnglesCFrame = CFrame.Angles(0, math.rad(YOrientation), 0)
local NewCFrame =, Position.Y + Size.Y/2, Position.Z)
ClientStructure:PivotTo(NewCFrame * NewAnglesCFrame)

I want the fence to be on the ground, not floating

You might also want to cast a ray from the endpoints of the part to the ground to see what they hit and then align it to a suitable height.