Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I animate a GUI menu procedurally?

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

✓ Accepted answer

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

2 comments

0

But would that make the next button spawn under the previous one?

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.