I have a table that lists different items within my game.
It looks sort of like this:
local items{
hat:4
leggings:3
}
I would like to make a script that clones a text label for every amount that I have within this table.
I currently am only able to make a clone each item, but I don’t know how to repeat clone for each amount. Any help would be greatly appreciated.
local Items = {
["Hats"] = 4;
["Leggings"] = 3;
};
for i,v in pairs(Items) do
print(i.." = "..v);
end;
This is just an example to show you how you can retrieve all items’ name and their amount by using a for loop
. You can use it to clone your TextLabel too for each item.
That is essentially what I currently have atm. My textlabel prints
“leggings:x3”
and “hats:x4” but I want to make it clone a label that says “hats” 4x and leggings x3, basically every time for each item. This has a purpose in my game but I can’t figure it out so how would I do this?
Im sorry if that was confusing but I mean I want it likes:
“hats”
“hats”
“hats”
So, a textlabel for item name, amount
I’m not quite sure what do you exactly mean, but if you want each text label with the name of the item as its text then you can do something like this:
for i,v in pairs(Items) do
for count = 1, v, 1 do
local Clone = TextLabel:Clone();
Clone.Text = i;
Clone.Parent = ScreenGui;
end;
end;
Obviously, you have to get your TextLabel and clone it, and set the parent to whatever you want it to be. I don’t know your game’s hierarchy so I just made a simple example so you can understand what’s going on.