Placement system offset error with rotated parts

Well I was doing a placement system and found that I couldn’t put things on the walls, I fixed that but I haven’t figured out how to replicate that on rotated walls


-- My mouse is based on raycasting, that's why the target surface and mouse hit are a Vector3

local function movePart()
	if mouse.Hit ~= nil then
		local X, Y, Z = mouse.Target.CFrame:ToEulerAnglesXYZ()
		local cf = ( * CFrame.Angles(X,Y,Z)) + (part.Size * mouse.TargetSurface / 2)
		part.CFrame = part.CFrame:Lerp(cf, 0.8)

The object rotation becomes the target orientation, but the object offset get’s glitchy
here’s an example

Does somebody have a clue of how do I fix it?

I got a solution, but if the bounding box of the models is not the same in all faces (for ex:,3,3) the model becomes glitchy and doesn’t fit in the walls