How to tween Model:SetPrimaryPartCFrame()

So how do you do it like miner haven’s placement system where everything is quint and buttery smooth

But that would only tween one individual part

2 Likes

You should use weldconstraints to weld all the parts to the PrimaryPart.

1 Like

Create a vector 3 value and tween it and use .Changed to set the CFrame of the model to a CFrame created from the Vector3.

Furthermore, this has been asked many times before.

1 Like

Miner haven’s source code I checked which does not have weld constraints
@berezaa Right?

A crucial part in tweening models is to have welds. See this tutorial for more information: Introduction to Tweening Models

1 Like

I already tried that and the tweens are not smooth because it is a grid placement system in a runservice thing so it does not work well with runservice

WeldConstraints don’t have to be made through code, they can also be created in studio.

Adding to OP’s reply and quoting from the linked thread:

If you strictly want all the parts to be anchored, this is a method you can probably bind to a CFrameValue tween and property change. But this is a complicated workaround.

As the post describes and previous replies, it’s the far easier choice to tween one anchored root and all the other parts welded to it.

2 Likes

If you really want to tween a model this way, create a dummy CFrameValue, tween its CFrame property, then connect a GetPropertyChangedSignal("CFrame") to it and make it call SetPrimaryPartCFrame accordingly.

1 Like

I already tried and it does not work smoothly, lemme tell ya.

Having welds to an anchored primary part is going to be less intensive than SetPrimaryPartCFrame.

That said, if you’re set on using that function, you can tween Value objects and use their Changed event:

local model = YOUR_MODEL
local goalCFrame = YOUR_GOAL_CFRAME

local cf = Instance.new('CFrameValue')
cf.Value = model.PrimaryPart.CFrame

local tween = game:GetService('TweenService'):Create(CF, TweenInfo.new(), {Value = goalCFrame})

-- Move the model
cf.Changed:Connect(function()
    model:SetPrimaryPartCFrame(cf.Value)
end)

-- Ensure cf can get garbagecollected
tween.Completed:Connect(function()
    tween:Destroy()
    cf:Destroy()
end)

tween:Play()
1 Like

I already tried and it does not work smoothly, lemme tell ya.

That’s mostly due to the time taken to move via that method, especially for large objects. That’s why the welded suggestion is very popular. Also you get the benefit of client prediction with the welded method.

1 Like