How would I make a list of things get written in a TextLabel?

What I specifically want to do and is unsure of how to do is changing a textlabel to either one or multiple different Items.Name.

What I am doing is:

for _, Items in pairs (ActualPlayer.Backpack:GetChildren()) do
	if Items:IsA("Tool") then
		ItemData.Text = (Items.Name)
	end
end

So it takes something from your inventory and puts it into a TextLabel, however doing it like this only takes 1 of the items and if it’s possible to seperate these items with a comma would be nice. How do I make the TextLabel include all of the items in

ActualPlayer.Backpack

I tried looking around but I can’t seem to find any answers.

I’m a little confused by what you’re asking for, but I think this solves it:

-- Changed "Items" to "Item"
local Tools = {}
for _, Item in pairs(ActualPlayer.Backpack:GetChildren()) do
	if Item:IsA("Tool") then
		table.insert(Tools, Item.Name)
	end
end

ItemData.Text = table.concat(Tools, ", ")
-- concat will expand out the table into a string with each element seperated by ", "
-- Example: {"Tool1", "Tool2", "Tool3"} -> "Tool1, Tool2, Tool3"
7 Likes

You can join all of the elements in a table using table.concat, as follows:

Edit: Ah! @ahpricot beat me to it!

local table1 = {"hi", "hello"}
local ListOfElements = table.concat(table1, ", ")

print(ListOfElements) -- Output: hi, hello
1 Like