Help putting a table in a list of text labels

Let’s say I have a menu at a restaurant. I have a table of our current options {Hotdog, Pizza, Water}
What I want to do is put the table contents on text labels on the menu. If you’re confused I’ll make another example we are at an auction. On the board shows recent bids. The current recent bids are {1$,5$,10$} I want to put the bids on a text labels which are on the board. I’ve been searching for other topics, but couldn’t find one to help me.

1 Like

Use a loop to iterate over the table.

local table = {}

for index, food in ipairs(table) do
-- put each food in text labels
end
1 Like

It would depend on how the table is structured.

Let’s say your table is structured like this:

local list = {
    "Hot Dog",
    "Pizza",
    "Water"
}

Your code for outputting text labels in a row displaying these items could be very simply done like so:

local frame = Instance.new("Frame")
frame.Name = "List"
frame.Size = UDim2.new(1, 0, 1, 0) -- Covers the entire area
frame.Parent = screenGui -- assuming you have one already

-- Setting the text labels
for i = 1, #list do
    local textLabel = Instance.new("TextLabel")
    textLabel.Name = i -- Each textLabel is marked by its number
    textLabel.Text = list[i] -- Get the value from the earlier list
    textLabel.Size = UDim2.new(1, 0, .1, 0) -- Arbitrary size
    textLabel.Position = UDim2.new(0, 0, .1 * (i - 1), 0) -- Position
    textLabel.Parent = frame -- Finally, parent
end
3 Likes

I’m getting this error: invalid argument #3 (string expected, got table)

I just did it on my end with the exact code I wrote and it worked.

How is your table structured? Because the only way you could be getting an error is if you had it structured like this:

local list = {
    {"Hot Dog"},
    {"Pizza"},
    {"Water"}
}

Make sure it’s like below, not like above:

local list = {
    "Hot Dog",
    "Pizza",
    "Water"
}

Figured out my problem thank you