Door Orientation not working

Hello Developers. I have been working on an open and close door Tween but have ran into an issue.
The open works fine and tweens 90 Degrees however the 2nd Tween for closing instead of going back -90 Degrees it
goes forward. I have tried a few different things for the last Hour but not sure what the issue is. I have dropped the
code and a GIF below. Sorry for the lag.
https://gyazo.com/90c891de551d8e91a2ee4d4de3b4e064

local Door = workspace.Door
local Main = Door.PrimaryPart
local TweenService = game:GetService("TweenService")
local DoorSwingInfo = TweenInfo.new()
local Tween = TweenService:Create(Main,DoorSwingInfo,{CFrame = Main.CFrame * CFrame.Angles(0,math.pi/2,0)})
local Tween2 = TweenService:Create(Main,DoorSwingInfo,{CFrame = Main.CFrame * CFrame.Angles(0,-math.pi/2,0)})


game:GetService("UserInputService").InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.K then
		Tween:Play ()
		wait(2)
		Tween2:Play ()
	end
end)
2 Likes

Is tween2 supposed to tween the door back to its original rotation? If that’s what you want, then the goal CFrame in it should probably be the original CFrame and not a CFrame rotated -90 degrees from the original CFrame.

local Tween = TweenService:Create(Main,DoorSwingInfo,{CFrame = Main.CFrame * CFrame.Angles(0,math.pi/2,0)})
local Tween2 = TweenService:Create(Main,DoorSwingInfo,{CFrame = Main.CFrame})
1 Like

Thanks for the reply! The issue is there’s gonna be multiple doors in-game and they go off one door function that’s why in trying to do it via degrees/radians.

I’m not sure if I understood. If you want it to rotate ninety degrees backwards in the second tween, then you should use a goal CFrame that is rotated ninety degrees backwards from the goal of the first tween. And the original cframe is rotated 90 degrees backwards from the goal of the first tween, which is rotated 90 degrees forward from the original.

If there’s multiple doors, couldn’t you just do something like this?

local doorTweens = {}
for i, door in ipairs(doors) do
    local pp = door.PrimaryPart
    local ppCf = pp.CFrame
    doorTweens[door] = {
        TweenService:Create(pp, DoorSwingInfo, {CFrame = ppCf * CFrame.Angles(0, math.pi * .5, 0)}),
        TweenService:Create(pp, DoorSwingInfo, {CFrame = ppCf})
    }
end

local function openDoor(door)
    local tweens = doorTweens[door]
    tweens[1]:Play()
    wait(2)
    tweens[2]:Play()
end
2 Likes