Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I SetToPrimaryPart this Model?

Asked by
Borrahh 265 Moderation Voter
4 years ago

Basically, I am tweening every single part of the model, how can I set to primary part, so I can only move one, then the others follow the Primary part

game.Workspace.LeftDoorEntrance.Part.ClickDetector.MouseClick:Connect(function()

    local TweenService = game:GetService("TweenService")

    local tweenInf = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
    local Properties = {CFrame = CFrame.Angles(0, -80, 0) + Vector3.new(-20.844, 57.8, 83.596)}
    TweenService:Create(game.Workspace.LeftDoorEntrance.Part, tweenInf, Properties):Play()
    TweenService:Create(game.Workspace.LeftDoorEntrance.Union, tweenInf, Properties):Play()
    TweenService:Create(game.Workspace.LeftDoorEntrance.MeshPart2, tweenInf, Properties):Play()

    local Propteries2 = {CFrame = CFrame.Angles(0, -180, 0) + Vector3.new(-21.274, 57.8, 83.676)}
    TweenService:Create(game.Workspace.LeftDoorEntrance.MeshPart, tweenInf, Propteries2):Play()
    TweenService:Create(game.Workspace.LeftDoorEntrance.MeshPart2, tweenInf, Propteries2):Play()
end)
0
Select the model, in the properties tab, choose the 'PrimaryPart' field and select the part which you want to set as the primary part Soban06 410 — 4y
0
I did that, I made the Part to be the PrimaryPart, I tween only the part and only the part moves, not the whole Model Borrahh 265 — 4y
0
If you want to tween your model without possibly separating it, you can weld up all parts to a PrimaryPart, and simply tween that PrimaryPart as the anchor (main part), if your goal is to tween its CFrame property. BestCreativeBoy 1395 — 4y

1 answer

Log in to vote
1
Answered by
Befogs 113
4 years ago

To tween an entire model, you'll have to use SetPrimaryPartCFrame, which moves the PrimaryPart and all parts in the model respective to the PrimaryPart. You can't tween for SetPrimaryPartCFrame directly, so you'll have to do this when the tween changes. Here's an example of how this could look.

local Model = game.Workspace.Model -- Your Model
local EndCFrame = CFrame.new(0,0,0) -- The CFrame you'd like to tween to

local TweenService = game:GetService("TweenService")
local CFrameValue = Instance.new("CFrameValue")
CFrameValue.Value = Model:GetPrimaryPartCFrame()

local Info = TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut)
local Tween = TweenService:Create(CFrameValue,Info,{Value = EndCFrame})
local Attach = CFrameValue.Changed:Connect(function()
    Model:SetPrimaryPartCFrame(CFrameValue.Value)
end)
Tween:Play()
Tween.Completed:Wait()
CFrameValue:Destroy()

I create the CFrameValue to have its value tweened because we cannot tween to SetPrimaryPartCFrame. When the CFrameValue's value changed we just SetPrimaryPartCFrame for the model. The final result will be that the model moves with the CFrameValue. Then we just destroy the CFrameValue when the tweening is over so there are no memory leaks!

Ad

Answer this question