List GUI using :GetChildren()

Heyo Devforum! I am making a menu and I want it to be super easy to update (Add foods/drinks). I am using a folder with values, the values are named to the food and then the script is supposed to clone a text lable/button to each value and to change the text to the specific food.

But when I attempt to do this it clones the text buttons to the correct amount but changes the text of all of them to the same value.

This is my code:

local button = script.TextButton
local foods = script.Parent.Parent.Menu.Food:GetChildren()

for i = 1, #foods do
	local food = button:Clone()
	food.Name = foods[1].Name
	food.Parent = script.Parent
	food.Text = foods[1].Name
end

How would I go about doing this?

Gui:

image

Script Location:
image

Please get back to me ASAP.

local button = script.TextButton
local foods = script.Parent.Parent.Menu.Food:GetChildren()

for i = 1, #foods do
	local food = button:Clone()
	food.Name = foods[i].Name
	food.Parent = script.Parent
	food.Text = foods[i].Name
end
2 Likes

Thanks, i’m still new to scripting so this helps a ton!

local t = {'a','b','c','d'}; -- etc.
for index, value in next, t do
print(index, value);
end;

So you won’t mess up next time because you forgot to use index, try to use the method above for the iterations