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).
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()
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