How do I position a Part right next to another Part at the side it came from? (using a script)

How do I position a Part right next to another Part at the side it came from using a script?

I think the image explains it a bit better

Skjermbilde2

I have no idea but I have tried some simple code halfing the Size of the TargePart and testing raycast but the size math relative to the position is the problem

Hey I believe I found the answer,
It needs some adjustments and it dosent include any orientation math but but here it is:

local otherPart = script.Parent.Part2

local part = script.Parent.Part1

-- Determine which side the part came from

local side = (part.Position - otherPart.position).Unit

-- Calculate the new position of the part

local newPosition = otherPart.position + side * (otherPart.Size / 2 + part.Size / 2)

-- Set the position of the part

part.CFrame = CFrame.new(newPosition)

Interesting how people are already using this lol.

Use Magnitude, instead of Unit.

he deleted his reply, I could see it was created by it

what… it only teleports the part into crazy positions