How do I make a part move a certain amount of studs away from another part?

If I have two parts, (PartA and PartB) and I do not know the orientation of either, but I would like to tween PartA’s Cframe to be moved more 5 studs away from point B’s how would I go about doing that?

local offset = partB.Position - partA.Position
partA.Position -= offset.Unit * 5

and if you want to tween you can like this

local offset = partB.Position - partA.Position
local targetPosition = partA.Position - offset.Unit * 5

local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(5)
local tween = TweenService:Create(partA, tweenInfo, [Position = targetPosition])
tween:Play()
1 Like