I need to make a opening tween overlap a closing tween if the closing tween is playing.
I’m making a door and I’m using TweenService to get the doors to open and close smoothly.
I have a problem where the door closes. The doors don’t really open back up right if the player is near it while the door is still closing.
I’ve tried using reference from my other game which used tweens for GUI. Since GUI can overlap a tween, I’m sure that it could work with parts.
I’m using two scripts for this as one is a module and one is a server script.
ServerScript:
local function openDoors()
if not debounce then
debounce = true
tweeningModule.Tween(doorL, {CFrame = openPosL}, .5, Enum.EasingStyle.Quint, Enum.EasingDirection.Out, 0, false, 0, false)
tweeningModule.Tween(doorR, {CFrame = openPosR}, .5, Enum.EasingStyle.Quint, Enum.EasingDirection.Out, 0, false, 0, false)
end
end
local function closeDoor()
if debounce then
debounce = false
tweeningModule.Tween(doorL, {Position = closePosL}, .5, Enum.EasingStyle.Quint, Enum.EasingDirection.Out, 0, false, 0, false)
tweeningModule.Tween(doorR, {Position = closePosR}, .5, Enum.EasingStyle.Quint, Enum.EasingDirection.Out, 0, false, 0, false)
end
end
-- Events
doorHitbox.Touched:Connect(function(hit)
if Players:GetPlayerFromCharacter(hit.Parent) then
openDoors()
wait(2)
closeDoor()
end
end)
ModuleScript:
local tweenService = game:GetService("TweenService")
local module = {}
function module.Tween(object, goal, duration: number, easingStyle, easingDirection, repeatCount, reverse, delayTime, waitUntilCompleted: boolean)
local tweenInfo = TweenInfo.new(
duration,
easingStyle,
easingDirection,
repeatCount,
reverse,
delayTime
)
local tween = tweenService:Create(object, tweenInfo, goal)
if object:FindFirstChild("Tween") then
object.Tween:Destroy()
end
tween.Parent = object
tween:Play()
if waitUntilCompleted == true then
tween.Completed:Wait()
tween:Destroy()
else
task.spawn(function()
tween.Completed:Wait()
tween:Destroy()
end)
end
end
return module