How to tween an anchored model?

I want to make a door system, and I want to make it work only for certain teams.

I have anchored model of door and I do not really know how to rotate it.
Can anyone give me an example or tutorial me how can I rotate a model?

(i searched devforum and found only unanchored model tweens)
Thanks for helping!

1 Like
local door = --[[PATH TO DOOR]]
local targetrotation = CFrame.Angles(math.rad(90), 0, 0) --May have to change axis depending on door model

local closedcf = door.CFrame --Save old rotation
local opencf = closedcf * targetrotation * CFrame.new(0, 0, door.Size.Z / 2)

TweenService:Create(door, TweenInfo.new(timetoopen), {
    CFrame = opencf
}):Play() --Opens door

wait(3)

TweenService:Create(door, TweenInfo.new(timetoclose), {
    CFrame = closedcf
}):Play() --Closes door

This code will rotate an instance 90 degrees then close it. Several variables will have to be changed and you may have to change the axis used in CFrame.Angles and CFrame.new. Alternatively, you can move the door to the desired position in studio, save the cframe for closed and open positions, and put them in the respective variables (opencf and closedcf).

3 Likes

You can’t tween a model directly, but you can tween the model indirectly by tweening a dummy CFrameValue with a Changed listener connected that will smoothly move the model with the tween. This will require the model’s PrimaryPart to be set.

local TweenService = game:GetService("TweenService")
local model = workspace.Model

local cframe = Instance.new("CFrameValue") -- create a dummy cframe value to tween
cframe.Value = model:GetPrimaryPartCFrame() -- set to current model's cframe to tween from current cframe
cframe.Changed:Connect(function(value) -- listen for the dummy cframe to change, and update model's cframe
	model:SetPrimaryPartCFrame(value)
end)

-- tween dummy cframe value, and the Changed listener will move the model smoothly
local tween = TweenService:Create(cframe, TweenInfo.new(5), {Value = CFrame.new(0, 5, 0)}) -- change to however you want to tween the model
tween:Play()

-- destroy the dummy cframe after the tween to prevent memory leaks
tween.Completed:Wait()
cframe:Destroy()
4 Likes

It does errors, “CFrame is not a valid member of Model”.
Thank you for trying to help me!

2 Likes

try local door = --[[PATH TO DOOR]].PrimaryPart, door must be connected to primarypart

2 Likes

Is there way to not set CFrame for each door manually?

2 Likes

It just does not tween, I see no errors in the output.
(EDIT: i have connected door to primarypart, please help someone)
please help me, someone!

1 Like

Oh… I forgot to put :Play() at the end.
Thank you so much!
EDIT: There’s a problem that it does not make entire model rotate

1 Like

Make sure the Model has a PrimaryPart set inside the Model

1 Like

Also you can do the trick of mine which is using the door animation without tweening but we are going to use Pivot rotation instead.

Reply if you are willing to.

1 Like

do you still need help? I have this model that I can give you as a reference .
ProDoor - Roblox

I basically tween a Cframe value. When the CFrame value change , I CFrame the door hinge so that it seems like I am CFraming an anchored part . However, the door is not anchored and it is just welded to the hinge for rotation . You can do some math to the door so that the door can be anchored . Other than that , the other parts should be anchored

1 Like

You can basically use Weld Constraint method in order to rotate doors. That’s the ony way to do it, and you will be using TweenService method too.