How can I make object tween back to original place

So I been making a elevator system recently and managed to get the door opening part of the script but when I try to close the doors the doors are offset meaning that they can get stuck like in middle of a certain spot such example is here:

Opening with CFrame.new(0,-2.1,0)
https://gyazo.com/d567a8ef535e7f79d23e5401e7030c38

Closing with CFrame.new(0,2.1,0)
https://gyazo.com/f5f9500a9954e545d9bb7c1efb48040a

What Im basically trying to do is get the same tween style of doors closing to their original position rather than getting stuck halfway

Code:

function CloseLeftDoors()
	local doorCloseLeft1 = {CFrame = script.Parent.Parent.Elevator.ElevatorDoor.LeftMiddlePart.CFrame * CFrame.new(0,0,2.1)}
	local doorCloseLeft2 = {CFrame = script.Parent.Parent.Elevator.ElevatorDoor.LeftGlass.CFrame * CFrame.new(0,0,-2.1)}
	local doorCloseLeft3 = {CFrame = script.Parent.Parent.Elevator.ElevatorDoor.LeftMiddle.CFrame * CFrame.new(0,2.1,0)}
	local doorCloseLeft4 = {CFrame = script.Parent.Parent.Elevator.ElevatorDoor.LeftDoor.CFrame * CFrame.new(0,0,0.9)}
	
	local Info = TweenInfo.new(2, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
	
	tweenService:Create(script.Parent.LeftMiddlePart, Info, doorCloseLeft1):Play()
	tweenService:Create(script.Parent.LeftGlass, Info, doorCloseLeft2):Play()
	tweenService:Create(script.Parent.LeftMiddle, Info, doorCloseLeft3):Play()
	tweenService:Create(script.Parent.LeftDoor, Info, doorCloseLeft4):Play()
end

function CloseRightDoors()
	local doorCloseRight1 = {CFrame = script.Parent.Parent.Elevator.ElevatorDoor.RightMiddlePart.CFrame * CFrame.new(0,0,-2.1)}
	local doorCloseRight2 = {CFrame = script.Parent.Parent.Elevator.ElevatorDoor.RightGlass.CFrame * CFrame.new(0,0,-2.1)}
	local doorCloseRight3 = {CFrame = script.Parent.Parent.Elevator.ElevatorDoor.RightMiddle.CFrame * CFrame.new(0,2.1,0)}
	local doorCloseRight4 = {CFrame = script.Parent.Parent.Elevator.ElevatorDoor.RightDoor.CFrame * CFrame.new(0,0,-0.9)}
	
	local Info = TweenInfo.new(2, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)

	tweenService:Create(script.Parent.RightMiddlePart, Info, doorCloseRight1):Play()
	tweenService:Create(script.Parent.RightGlass, Info, doorCloseRight2):Play()
	tweenService:Create(script.Parent.RightMiddle, Info, doorCloseRight3):Play()
	tweenService:Create(script.Parent.RightDoor, Info, doorCloseRight4):Play()	
end
function OpenLeftDoors()
	local doorOpenLeft1 = {CFrame = script.Parent.LeftMiddlePart.CFrame * CFrame.new(0,0,-1.8)}
	local doorOpenLeft2 = {CFrame = script.Parent.LeftGlass.CFrame * CFrame.new(0,0,1.8)}
	local doorOpenLeft3 = {CFrame = script.Parent.LeftMiddle.CFrame * CFrame.new(0,-1.8,0)}
	local doorOpenLeft4 = {CFrame = script.Parent.LeftDoor.CFrame * CFrame.new(0,0,-0.9)}
	
	local Info = TweenInfo.new(2, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
	
	tweenService:Create(script.Parent.LeftMiddlePart, Info, doorOpenLeft1):Play()
	tweenService:Create(script.Parent.LeftGlass, Info, doorOpenLeft2):Play()
	tweenService:Create(script.Parent.LeftMiddle, Info, doorOpenLeft3):Play()
	tweenService:Create(script.Parent.LeftDoor, Info, doorOpenLeft4):Play()
end

function OpenRightDoors()
	local doorOpenRight1 = {CFrame = script.Parent.RightMiddlePart.CFrame * CFrame.new(0,0,1.8)}
	local doorOpenRight2 = {CFrame = script.Parent.RightGlass.CFrame * CFrame.new(0,0,1.8)}
	local doorOpenRight3 = {CFrame = script.Parent.RightMiddle.CFrame * CFrame.new(0,-1.8,0)}
	local doorOpenRight4 = {CFrame = script.Parent.RightDoor.CFrame * CFrame.new(0,0,0.9)}
	
	local Info = TweenInfo.new(2, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)

	tweenService:Create(script.Parent.RightMiddlePart, Info, doorOpenRight1):Play()
	tweenService:Create(script.Parent.RightGlass, Info, doorOpenRight2):Play()
	tweenService:Create(script.Parent.RightMiddle, Info, doorOpenRight3):Play()
	tweenService:Create(script.Parent.RightDoor, Info, doorOpenRight4):Play()	
end
2 Likes

what i do for something like elevator doors is to simply add parts for where the doors will end up, and where they close

alternatively you can just retrace your tween-steps when you did it the first time

I don’t understand why it cant tween back to its original spot though since im tweening it same amount that is goes out with

I don’t understand why you would need 2 doors to open and another 2 doors to close, it would be even more easier if you just used 2 doors to open and close.

1 Like

The code is separated for left and right door side I just named it incorrectly

1 Like

Hey there is an option to tween it back in the tween info table WITHOUT having to create another tween. You can set the 5th parameter of the tween info table to true, and it will automatically do the reverse of the tween as well after it has completed!

Hope this helped, and mark this as the solution if this solved your problem!

1 Like

what 5th parameter are you talking about the info?

1 Like

Here is the Developer Hub reference of TweenInfo.new. The 5th parameter is reverses which is a bool value. If it is true, then it will undo the Tween once it has completed. If it is false, the Tween will just end right there.

1 Like

So will I need to keep my units for the door closing or have them same as the opening door numbers

1 Like

No, you will not have to keep the stuff for closing the door as reverses just reverts it back to the position it was before the Tween started.

1 Like