Move Part away from Part (Intersected Parts)


Example:

BLUE PART: The object to move
YELLOW SQUARE: Origin of the blue part (Origin might be the center of blue part as well)

How can I accomplish moving a part away from the wall(s) it’s intersecting with?
From A (left of image) to B (right of image)

I hope this example makes sense; any help is appreciated!

You’re going to need to use the tween service

local TS = game:GetService("TweenService")
local block = script.Parent
local blockB = game.Workspace:FindFirstChild([Name Of the block you want to move to here])
local blockBP = blockB.Position

local blockTween = TweenInfo.new(
2, -- Time of tween
Enum.EasingStyle.Linear, -- Moves back and forth linear
Enum.EasingDirection.Out, -- Moves out of origin
-1, -- This makes the tween run infinitely
true, -- It can reverse meaning it goes back and forth
0 -- Delay time
-- Feel free to change any of these things if you want
)

local newTween = TS:Create(block, blockTween, {Position = blockBP}) -- Makes part A move to part B's position

newTween:Play()