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)
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!