Hello! I am making a gui and I want the ImageButton elements to all tween up the screen, one after the other. The code seems to work and the tweens play one after the other, but the positioning is my issue. (See Attatched Video)
Any Ideas as to why this is happening, or how to help?
Here is the code.
for _, Item in pairs(ItemSub:GetChildren()) do
if Item:IsA("ImageButton") then
local xPos = Item.Position.X.Scale
Item.Position = UDim2.new(xPos + 1.165, 0, 4, 0)
end
end
task.wait(.025)
for _, Item in pairs(ItemSub:GetChildren()) do
if Item:IsA("ImageButton") then
Item:TweenPosition(
UDim2.new(Item.Position.X.Scale, 0, 0.024, 0),
Enum.EasingDirection.Out,
Enum.EasingStyle.Back,
.3)
task.wait(.15)
end
end
Two loops are used, one for settings the positions of the gui elements, and one for tweening to positions of the gui elements.
(p.s. I don’t plan on uploading this game this is being made just for fun. I know that roblox doesn’t like pokemon)
I’m assuming the initial position of all these gui buttons are the same, so when you just add +1.165, they are all still the same and they kinda stack together as shown in the video. Use the index variable and multiple that with the base addition of 1.165 to fix the positions. Then button 1 = 1.165 but button 2 = 2.33. In order for this to work, ItemSub can only contain the buttons, nothing else. So you might have to make a special folder for them or something.
Edit: I just realized 1.165 is literally more than the entire screen. Why dont you just make the buttons all have their x position be like 0.5 and just add 0.05 or something smaller like that?
1.165 is because the frame that contains the items. (It normally has a UIPageLayout) is as small at the buttons being shown, so they need to be positioned off-frame to line up with the buttons that will be shown on the frame with the UIPageLayout.
And also, if you don’t mind, maybe you can give a code example of what you are stating in the first half?
This is your first loop. I changed it so it uses the index, but I don’t think it’ll work because 1.165 is really big. Also, in order for the index to be accurate, the folder cant skip through other elements, so you should put all the buttons in a special folder for this.
for i, Item in pairs(ItemSub:GetChildren()) do
if Item:IsA("ImageButton") then
local xPos = Item.Position.X.Scale
Item.Position = UDim2.new(xPos + (1.165 * i), 0, 4, 0)
end
end
local Index = 0
for _, Item in pairs(ItemSub:GetChildren()) do
if Item:IsA("ImageButton") then
Index += 1
local xPos = Item.Position.X.Scale + (Index * 1.165)
task.wait(.15)
Item:TweenPosition(
UDim2.new(xPos, 0, 0.024, 0),
Enum.EasingDirection.Out,
Enum.EasingStyle.Back,
.3
)
end
end
You may need to move Index += 1 to after ‘xPos’ is calculated.