Trying to make the Studio Select tool in-game but having problems to script the collisions

I want to make the selection tool the studio has in the game so you can build and etc. I have almost finished it in scripting but i came across to a problem i can’t solve.

Basically i am using mouse.Hit and Mouse.Target to detect the mouse Position on where the Object should be placed. Just like the Select tool when you move the object around i want it to be placed on top/side/ of the other object your mouse is aiming at.

For example when you drag the part around the baseplate i want it to be on top just like this
image

But it’s being placed inside it like this
image

I already tried to calculate the Position with this

Object.Position = Vector3.new(mouse.Hit.p.X,mouse.Hit.p.Y + Object.Size.Y/2 ,mouse.Hit.p.Z) 

which works but this comes with a problem

Every part and such can have orientation and because of that how can you know that in order for an object to stay on top or side you will need to change the X value instead of the Z or the Y?

An idea that i had was using mouse.TargetSurface which returns the part the mouse is aiming at if it’s facing Left/Right/Top/Button but due to orientation that objects can be rotated if an object has been rotated the right side of it won’t be the same with a part that hasn’t been rotated and again you don’t know if you need to change the X,Y,Z value in order for it to be on top/side