TweenService door plays tween later than it should and I don't know why

Hello developers.

Today I brought it upon myself to create some new doors for my game as I made the old ones in a rush. I decided to use TweenService for the doors so it would have a smoother animation, but when I tested it the tween played 2-3 seconds after I clicked the button and I am not sure why.

Here is a video of my issue:

My code:

--// Services
local TweenService = game:GetService("TweenService")

--// Variables
local ScriptedComponents = script.Parent.ScriptedComponents
local Button1 = ScriptedComponents.Button1.ClickDetector
local Button2 = ScriptedComponents.Button2.ClickDetector
local DoorModel = ScriptedComponents.DoorModel

--// Settings
local TweenData = TweenInfo.new(2, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)
local CloseGoal = {Position = Vector3.new(DoorModel.Position.X, DoorModel.Position.Y + 7, DoorModel.Position.Z)}
local OpenGoal = {Position = Vector3.new(DoorModel.Position.X, DoorModel.Position.Y + 0, DoorModel.Position.Z)}

--// Data
local Debounce = false

--// Tweens
local TweenClose = TweenService:Create(DoorModel, TweenData, CloseGoal)
local TweenOpen = TweenService:Create(DoorModel, TweenData, OpenGoal)

--// Functions
function Door()
	if Debounce == false then
		Debounce = true
		
		TweenOpen:Play()
		TweenOpen.Completed:Wait()
		wait(2)
		TweenClose:Play()
		TweenClose.Completed:Wait()
		
		Debounce = false
	end
end

--// Main
Button1.MouseClick:Connect(function()
	Door()
end)

Button2.MouseClick:Connect(function()
	Door()
end)

Any and all help is appreciated, thank you!

You have your CloseGoal and OpenGoal backwards.

Here is how it should be:

local CloseGoal = {Position = Vector3.new(DoorModel.Position.X, DoorModel.Position.Y + 0, DoorModel.Position.Z)}
local OpenGoal = {Position = Vector3.new(DoorModel.Position.X, DoorModel.Position.Y + 7, DoorModel.Position.Z)}

The OpenGoal should raise the part up by 7 and the CloseGoal should lower it back to its original position. You had it in the opposite way of CloseGoal raising by 7 and OpenGoal lowering it.

1 Like

What a simple mistake I missed, than you for the help!

2 Likes

No problem! Happens to us all at some time lol

1 Like