Sliding Doors Tween seems to messed up

Hello! I’m trying to make a Door Tween, where 2 Doors slide open whenever I type a command I made. I’m using OOP in this script, and I’m new to it (not relevant to the issue). The doors seem to go the opposite way, and then go where they were supposed to go.

Video that shows what happens:

Relevant Code (not the whole script):

function DoorModule:OpenDoor()
	if self.isOpen == false then
		local LeftDoorTween = TweenService:Create(self.Model.LeftDoor, TweenInfo.new(self.Time, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0), {Position = self.Model.LeftDoor.Position - Vector3.new(0, 0, self.Model.LeftDoor.Size.Y)})
		local RightDoorTween = TweenService:Create(self.Model.RightDoor, TweenInfo.new(self.Time, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0), {Position = self.Model.RightDoor.Position + Vector3.new(0, 0, self.Model.RightDoor.Size.Y)})
		
		LeftDoorTween:Play()
		RightDoorTween:Play()
		self.isOpen = true
		
	else
		warn(self.Model.Name .. " is already open!")
	end
end

function DoorModule:CloseDoor()
	if self.isOpen == true then
		local LeftDoorTween = TweenService:Create(self.Model.LeftDoor, TweenInfo.new(self.Time, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0), {Position = self.Model.LeftDoor.Position + Vector3.new(0, 0, self.Model.LeftDoor.Size.Y)})
		local RightDoorTween = TweenService:Create(self.Model.RightDoor, TweenInfo.new(self.Time, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0), {Position = self.Model.RightDoor.Position - Vector3.new(0, 0, self.Model.RightDoor.Size.Y)})

		LeftDoorTween:Play()
		RightDoorTween:Play()
		self.isOpen = false

	else
		warn(self.Model.Name .. " is already closed!")
	end
end

If you have any other ideas on how I could improve on this, please tell me!

It seems to be behaving as normal in the video. It closes when the close function is called, and opens when the open function is called.

Can you go more in depth of what the issue is?

The doors seem to go inside of each other when opening and closing. I want it, so it just opens and closes without overlapping.

Oh, i see.

Try this code out.

function DoorModule:CloseDoor()
	if self.isOpen == true then
		local LeftDoorTween = TweenService:Create(self.Model.LeftDoor, TweenInfo.new(self.Time, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0), {Position = self.Model.LeftDoor.Position + Vector3.new(0, 0, self.Model.LeftDoor.Size.Y/2)})
		local RightDoorTween = TweenService:Create(self.Model.RightDoor, TweenInfo.new(self.Time, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0), {Position = self.Model.RightDoor.Position - Vector3.new(0, 0, self.Model.RightDoor.Size.Y/2)})

		LeftDoorTween:Play()
		RightDoorTween:Play()
		self.isOpen = false

	else
		warn(self.Model.Name .. " is already closed!")
	end
end
function DoorModule:OpenDoor()
	if self.isOpen == false then
		local LeftDoorTween = TweenService:Create(self.Model.LeftDoor, TweenInfo.new(self.Time, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0), {Position = self.Model.LeftDoor.Position - Vector3.new(0, 0, self.Model.LeftDoor.Size.Y/2)})
		local RightDoorTween = TweenService:Create(self.Model.RightDoor, TweenInfo.new(self.Time, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0), {Position = self.Model.RightDoor.Position + Vector3.new(0, 0, self.Model.RightDoor.Size.Y/2)})
		
		LeftDoorTween:Play()
		RightDoorTween:Play()
		self.isOpen = true
		
	else
		warn(self.Model.Name .. " is already open!")
	end
end

The reason why it’s overlapping is because you are moving it with the entire width. You have to divide the width by 2.

I’ve already tried that, it still overlaps, but now it only goes half the distance at the end.

I’m a little confused, it overlaps but it doesn’t reach the end of the tween? Could you provide a screenshot.

After the tween:

Still overlaps in the middle of the tween:
Screenshot_677

I see, try changing the easing direction to InOut or In. If that doesn’t work, I’ll try to replicate the issue myself.

Same issue. Tried changing the Enum.EasingDirection to InOut and In.

self.Model.RightDoor.Position - Vector3.new(0, 0, self.Model.RightDoor.Size.Y/2)

I noticed that the Vector you use to modify the door position, uses the Y size of the door on the Z axis? Is there any particular reason for that?

The door’s length is on the Y axis, I should maybe fix that.
Screenshot_678

Found the issue. Had to change these lines:

local LeftDoorTween = TweenService:Create(self.Model.LeftDoor, TweenInfo.new(self.Time, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0), {Position = self.Model.LeftDoor.Position - Vector3.new(0, 0, self.Model.LeftDoor.Size.Y)})
local RightDoorTween = TweenService:Create(self.Model.RightDoor, TweenInfo.new(self.Time, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0), {Position = self.Model.RightDoor.Position + Vector3.new(0, 0, self.Model.RightDoor.Size.Y)})

to:

local LeftDoorTween = TweenService:Create(self.Model.LeftDoor, TweenInfo.new(self.Time, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0), {CFrame = self.Model.LeftDoor.CFrame * CFrame.new(-self.Model.LeftDoor.Size.Y / 2, 0, 0)})
local RightDoorTween = TweenService:Create(self.Model.RightDoor, TweenInfo.new(self.Time, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0), {CFrame = self.Model.RightDoor.CFrame * CFrame.new(self.Model.RightDoor.Size.Y / 2, 0, 0)})

I see, I tried to replicate the issue, but there was no issue to be found.

Happy to see that you found the fix!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.