How come SetPrimaryPartCFrame sets the whole model CFrame with all the parts but Primarypart.CFrame in my tween doesn't?

I’m trying to tween a model with multiple parts and when using CFrame the SetPrimaryPartCFrame positioned my whole model to where the tween starts off but the tween only tweens the primary part. How can I make the whole model tween like how SetPrimaryPartCFrame?

Plant = game.ReplicatedStorage.PlantingObjects.CabbageSeed:Clone()
Plant.Parent = Soil.Parent
local PlantCf = Plant:GetPrimaryPartCFrame()
local SoilCF = CFrame.new(Soil.CFrame.X, Soil.CFrame.Y - 5, Soil.CFrame.Z)
Plant:SetPrimaryPartCFrame(SoilCF * CFrame.Angles(math.rad(0), math.rad(0), math.rad(90))) -- This set the whole model. The Tween:Create() doesn't...
GrowTime = 10 / Divide
Tween = TweenInfo.new(GrowTime)
SoilCF = Soil.CFrame
local TweenPlant = TweenService:Create(Plant.PrimaryPart, Tween, {CFrame = SoilCF * CFrame.Angles(math.rad(0), math.rad(0), math.rad(90))})
print(SoilCF)
TweenPlant:Play()

You can create a CFrameValue where the instance’s values is set to the initial CFrame. This CFrameValue is what you will tween to the desired CFrame and use a Heartbeat event to use SetPrimaryPartCFrame to CFrame the model:

local CF_Value = Instance.new("CFrameValue")
local Tween = TweenService:Create(CF_Value, Tween, {Value = SoilCF * CFrame.Angles(0, 0, math.rad(90))})
local update

CF_Value.Value = Plant:GetPrimaryPartCFrame()
update = game:GetService("RunService").Heartbeat:Connect(function()
   Plant:SetPrimaryPartCFrame(CF_Value.Value)
end)

Tween:Play()
Tween.Completed:Connect(function()
    updateCon:Disconnect()
    Tween:Destroy()
    CF_Value:Destroy()

    updateCon = nil
    Tween = nil
end)

I recommend looking at this guide to tweening models.

The expectation of this method is that the rest of the parts in your model are unanchored and welded to the PrimaryPart. If this isn’t done, then yes only the PrimaryPart would get tweened.

1 Like