#Why doesn't my GUI tween when closing?

1 messages · Page 1 of 1 (latest)

lucid oak
#

basically when I open the gui its tween is like rising it up and it should go back down when I close it. this is my first time doing tweening and idk if its outdated but I asked chatgpt to help and it couldnt fix it. pls help me

tight heart
robust mural
#

use

#
tween.Completed:Connect(Function()
olive laurel
#
local TweenService = game:GetService("TweenService")

local shopOpen = script.Parent:WaitForChild("Open")
local shopFrame = script.Parent:WaitForChild("Shop")
local closeButton = shopFrame:WaitForChild("Close")

local visible = false

local tweenInPosition = UDim2.new(0.215, 0, 0.167, 0)
local tweenOutPosition = UDim2.new(0.214, 0, 0.818, 0)

shopFrame.Position = tweenOutPosition
shopFrame.Visible = false

local tweenInfo = TweenInfo.new(
    0.3,
    Enum.EasingStyle.Sine,
    Enum.EasingDirection.Out
)

shopOpen.MouseButton1Click:Connect(function()
    if not visible then
        shopFrame.Visible = true

        local tweenIn = TweenService:Create(shopFrame, tweenInfo, {Position = tweenInPosition})
        tweenIn:Play()

        shopOpen.Visible = false
        visible = true
    end
end)

closeButton.MouseButton1Click:Connect(function()
    if visible then
        local tweenOut = TweenService:Create(shopFrame, tweenInfo, {Position = tweenOutPosition})
        tweenOut:Play()
        tweenOut.Completed:Wait()
        shopFrame.Visible = false
        shopOpen.Visible = true
        visible = false
    end
end)
#

use tweenservice and .completed

#

tweenposition still works but kinda outdated and/or unoptimized