First raycasts are way more efficient than .Touched and way more precise, they does not cost at all a lot performance. Second as I can see you are trying to prevent part collides? Then you opt to use raycasts but not difference of position, else it might be extremely inaccurate dealing with huge or extreme vector objects.
You could also calculate the distance to the edge of both Parts (for example if Part A is 10x 4 x 12 studs you could take its Position and calculate the edge faces to be 1/2 the X,Y,Z values.
Do that for both Parts and you can use math to determine if the edges are at the same point and move them according to their Positions + or - the 1/2 X,Y,Z values.
I usually use GetTouchingParts instead of Touched, since touched is a lot (lot is an understatement) less accurate.
If the parts are cancollide off. You’ll have to do a little “hack” to get it working.
local TouchThread = part.Touched:Connect(function()end) --// Start the touch event.
local parts = part:GetTouchingParts() --// Returns Table full of parts. Look for the part(s) that push it.
TouchThread:Disconnect() --// Kill the Touched Event.