Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

Single button open and close tweened GUI frame?

Asked by 3 months ago
Edited 3 months ago

--(Here is what I tried coding with I want the project to tween from the bottom of the screen upward and back down separately when clicked multiple times. But only with one button to control this. I am not great at coding so I have tried searching on Youtube and also through peoples creations have yet to get this to work with a single button. Can someone help give me the solution to this? If not it is alright I can just use a two button method I guess.)

function pressed()
local ShopFrame = script.Parent.Parent.ShopFrame
    local toggle = false

    if not toggle then

        toggle = true
        ShopFrame:TweenPosition(UDim2.new(0, 75,1, 10), 'Out', 1)
        ShopFrame.Visible = false

    else

toggle = false
        ShopFrame:TweenPosition(UDim2.new(0, 75,0.2, 10), 'Out', 1)
        ShopFrame.Visible = true
    end
    end
script.Parent.MouseButton1Down:connect(pressed)

1 answer

Log in to vote
0
Answered by 3 months ago

Try this it should work

local Shop = game.Players.LocalPlayer.PlayerGui.ScreenGui.TextLabel
local states = {0,1}
local selected = 0
script.Parent.MouseButton1Click:Connect(function()
    selected += 1
    local chosenState = (selected%2)
    print(chosenState)
    if states[chosenState] == 0 then
        Shop:TweenPosition(
            UDim2.new(0.322, 0,0.207, 0),
            Enum.EasingDirection.Out,
            Enum.EasingStyle.Linear,
            1,
            false   
        )
    else
        Shop:TweenPosition(
            UDim2.new(0.326, 0,0.4, 0),
            Enum.EasingDirection.Out,
            Enum.EasingStyle.Linear,
            1,
            false   
        )
    end 
end)



0
Thank you so much this worked almost entirely.Changed local Shop to = script.Parent.Parent.ScrollableFrame, local selected = 1, and input the correct positions. Joshuagibson2 16 — 3mo
0
Also added the Tween at the beginning of the script to close it instantly. Joshuagibson2 16 — 3mo
0
No problem glad to help mikey2019d 38 — 3mo
Ad

Answer this question