How to make Model:SetPrimaryPartCFrame() without changing the orientation?

I’m trying to make my script Tween a model by its PrimaryPart. The problem is that the model’s primarypart’s orientation isn’t the same as the CFrame’s position of the Soil part or SoilCF. How can I fix the script so I don’t have to change the PrimaryPart’s orientation to 0, 0, 0 and not change the Soil’s orientation but just never change the orientation just the position but still serve the tweening purpose?

Plant = game.ReplicatedStorage.PlantingObjects.WheatSeed: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)
GrowTime = 10 / Divide
Tween = TweenInfo.new(GrowTime)
SoilCF = Soil.CFrame
local TweenPlant = TweenService:Create(Plant.PrimaryPart, Tween, {CFrame = SoilCF})
print(SoilCF)
TweenPlant:Play()
2 Likes

I believe you can just take the Position from the plant Model CFrame, and create a new CFrame with only that, instead of copying the entire CFrame including the orientation.

local PlantCf = Plant:GetPrimaryPartCFrame()

local SoilCF = CFrame.new(PlantCf.Position)
Plant:SetPrimaryPartCFrame(SoilCF)

In other words, just use the .Position from the PlantCf.

Well that wouldn’t work as SoilCF is the Soil’s CFrame not the model. What you put would just set the CFrame as the same value. If I’m wrong then please tell me somemore information behind your reply… Thanks

Sorry, I think I misread the OP. Why don’t you just tween the .Position instead of the .CFrame?

The problem is I want to tween a whole model and model’s don’t have a position… And If I do primarypart position then only the primarypart tweens

Have you tried un-anchoring, and welding, all of the parts beside the PrimaryPart, to the PrimaryPart? This is the only efficient way I know of doing this.

Here is a nice plugin I use frequently, that automatically welds parts together.

Just select the PrimaryPart first, and then all of the parts you want to weld to it, and press the “Weld All” button.

Thanks for the plugin. I’m going to try it and I hope it works!

You can just run this bit of code instead:

Model:SetPrimaryPartCFrame(CFrame.new(NewCFrame) * CFrame.Angles(math.rad(Model.PrimaryPart.Orientation.X), math.rad(Model.PrimaryPart.Orientation.Y), math.rad(Model.PrimaryPart.Orientation.Z))

When you do CFrame.new() alone it resets the orientation back to 0. So you multiply that with CFrame.Angles() to set the orientation you wish to use.

3 Likes

Adding on don’t forget to use math.rad()! or rotations are not going to be what you want.

4 Likes