local relative = pos - target.Position if relative.y + (target.Size.y / 2) > target.Size.y - .1 then preview.CFrame = preview.CFrame + Vector3.new(0,(preview.Size.y / 2),0) end if relative.y - (target.Size.y / 2) < (target.Size.y * -1) + .1 then preview.CFrame = preview.CFrame - Vector3.new(0,(preview.Size.y / 2),0) end if relative.x + (target.Size.x / 2) > target.Size.x - .1 then preview.CFrame = preview.CFrame + Vector3.new((preview.Size.x / 2),0,0) end if relative.x - (target.Size.x / 2) < (target.Size.x * -1) + .1 then preview.CFrame = preview.CFrame - Vector3.new((preview.Size.x / 2),0,0) end if relative.z + (target.Size.z / 2) > target.Size.z - .1 then preview.CFrame = preview.CFrame + Vector3.new(0,0,(preview.Size.x / 2)) end if relative.z - (target.Size.z / 2) < (target.Size.z * -1) + .1 then preview.CFrame = preview.CFrame - Vector3.new(0,0,(preview.Size.x / 2)) end
Script that will move a part and move it so that it doesn't clip through mouse.target. Problem here is that size doesn't change with orientation, so anything but the default will have the part offset.
Had to write a script to swap the x and z values if the lookvector.z was greater than -1.