Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I animate a GUI menu procedurally?

Asked by
alibix123 175
8 years ago

I have a menu that will have 3 buttons. When the player enters I want all the buttons to slide into view one after the other. the problem is that I don't really want to put a script into each button to animate because I think that would be messy and I could need to add more buttons in the future. Here is my code that slides in a text button:

local frame = script.Parent -- the frame that holds the menu
for _,gui in pairs(frame:GetChildren()) do -- getting all the text buttons
    if gui and gui:IsA("TextButton") then
        gui:TweenPosition(UDim2.new(0.05, 0, 0.1, 0), Enum.EasingDirection.Out, "Quad", 5) -- animating the single text button I have in my screen gui
    end
end

So how would I make the script so that:

  • Gets all text buttons (done)
  • Animates them into the screen (done)
  • After the first button, the next button will come into view under the first button by a fixed amount (not done)

How would I do this? I'm guessing something to do with table indexes which I am not good at...

1 answer

Log in to vote
1
Answered by 8 years ago

Correct me if I'm wrong, but could you not use spawn()?

--edited to fix the positions.

local counter = 0
local gSize = (put size here)
local frame = script.Parent -- the frame that holds the menu
for _,gui in pairs(frame:GetChildren()) do -- getting all the text buttons
    if gui and gui:IsA("TextButton") then
       spawn(function()
     gui:TweenPosition(UDim2.new(0.05, 0, 0.1+(gSize*counter), 0), Enum.EasingDirection.Out, "Quad", 5) -- animating the single text button I have in my screen gui
    end)
    counter = counter + 1
    wait(how ever long until the next one needs to appear)
    end
end
counter = 0

0
But would that make the next button spawn under the previous one? alibix123 175 — 8y
0
It's hard to explain, but no that wouldn't. You'd have to change line 5 to make it change the position, based on a variable. TinyPanda273 110 — 8y
Ad

Answer this question