How would a building system like this be achieved

Hey there I am trying to achieve a placing system like the gif shown below, I have already attempted it myself by finding the difference between the mouse.hit and the starting point, and then find the difference between the two (which works to a certain extent) but has many bugs and doesn’t seem as stable. However, if anyone has any ideas it would be great to hear them! thanks so much for your time.
~Fax/Flamingoboi