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!