Tweening a weld

I am trying to make a piston system but I wont get it working. I can’t seem to wrap my head around ToObjectSpace and welds.

Heres a gif representing what I want the parts to do with the White cube being Part1 and the Black cube being Part0:

WeldCFrame

This is my attempt at making this:

local Piston = script.Parent;

local weld = Instance.new("Weld");
weld.Parent = Piston;

weld.C0 = Piston.Part0.CFrame:Inverse();
weld.C1 = Piston.Part1.CFrame:Inverse();

weld.Part0 = Piston.Part0
weld.Part1 = Piston.Part1

local ts = game:GetService("TweenService");

local cfValue = Instance.new('CFrameValue')
cfValue.Value = weld.C0

local base = weld.C0

cfValue.Changed:Connect(function()
	local travel = weld.Part0.CFrame + cfValue.Value.Position;
	weld.C0 = travel:ToObjectSpace(weld.Part1.CFrame)
end)

local goal = {Value = CFrame.new(weld.Part0.CFrame.LookVector * 5)}

local cfTween = ts:Create(cfValue,TweenInfo.new(10),goal)
cfTween:Play()

wait(3)

ts:Create(weld.Part1, TweenInfo.new(4), {Position = weld.Part1.Position + Vector3.new(0,5,0)}):Play()

How would I recreate this in a script?

maybe try to use motor6d instead of using weld ?

Doesn’t Motor6D use the same technology as Weld?

weld are for keeping part at the same distance
motor6d are for moving part

or you can just use WeldConstraint because you can still move part that are being welded to other part

The thing with WeldConstraints though are that they don’t work with tweens

did you try to unanchor part0 yet

yes its just the math that is wrong

I realise im about 2 years late but have you ever found a solution? Currently got a similar problem and ive got no idea on how to fix it…