Hello, I’m having a bit of trouble with a thing I’m working on. My issue is, I need to clone a Frame(which I did by using a for loop (the frame has to be cloned the same amount of items there are in the ModuleScript)) and that Frame has a TextLabel that has to have different texts based on the info from a ModuleScript (name of the item)<— I tried doing that with a for loops as well/ and I can’t get this to work please help if you can Thank you!
This is the code that controls that/
for number = 1, TotalItems do
local new = script.Cell:Clone()
for i, v in pairs(Data)do
new.Rarity.Value = v.Rarity
new.name.Value = v.Name
end
new.Parent = script.Parent.Main.Back
end
I also thought that, but it’s not it clones the ‘cell’ and then makes the name.value only one Value instead of being different values in different cells
Hmm I’m not sure what you’re using since you didn’t show us what “Data” is but
These 2 lines intrigue me new.Rarity.Value = v.Rarity new.name.Value = v.Name
What is “Rarity” and “Name”? Are they values? If so shouldn’t you be using: new.Rarity.Value = v.Rarity.Value new.name.Value = v.Name.Value
local Items= {
{
Name = "Sword";
Coin = 2.5;
Shard = 0;
Year = 2020;
Rarity = "Common";
Chance = 25
},
{
Name = "Ninja Star";
Coin = 3.5;
Shard = 0;
Year = 2020;
Rarity = "Common";
Chance = 25
},
{
Name = "Blaster";
Coin = 5;
Shard = 0;
Year = 2020;
Rarity = "Common";
Chance = 25
},
{
Name = "Bell";
Coin = 6.3;
Shard = 0;
Year = 2020;
Rarity = "Uncommon";
Chance = 24
},
{
Name = "Pet";
Coin = 7;
Shard = 0;
Year = 2020;
Rarity = "Rare";
Chance = 1
}
}
return Items
and v.Name gets the Item name and it should set the Value of each in one of the cloned ‘cells’ to each on of the item names (sorry I’m not so good at explaining)
by reading the code now I understand,you’re not getting any index on the dictionary since all of the dictionary index values are unnamed
Also you’re not searching for the indexes inside the dictionary just running a loop though it
for number = 1, TotalItems do
local new = script.Cell:Clone()
for i, v in pairs(Data)do
new.Rarity.Value = v[i].Rarity
new.name.Value = v[i].Name
end
new.Parent = script.Parent.Main.Back
end
Just saying but according to your code you will be overwriting the values lots of times.
Edit:accidental uppercase “i” and corrected myself over something
So because in my dictionary the values are unnamed this doesn’t work?
Also that code is all I have to do to fix it, sorry I just want to learn more about this
There’s nothing to be sorry!
Programming is a learning process and everyone does a mistake here and there
Also oh I just noticed what you’re trying to acheive(trying to display all the items),and this code should work properly
for number = 1, TotalItems do
local new = script.Cell:Clone()
for i, v in pairs(#Data)do
new.Rarity.Value = Data[i].Rarity
new.name.Value = Data[i].Name
end
new.Parent = script.Parent.Main.Back
end
Also correcting myself overwriting won’t happen,sorry just noticed now that you were cloning the frames!
I’m so sorry again, I tried using the code you provided me with, but now instead of it cloning and not assigning the values it, assigns a single value (The pet for the name, and Rare for rarity) to all of the cells. You don’t have to but if you could help me with this it would be great.
My fault, sorry, I forgot to remove the other loop when I modified the new one
for i, v in pairs(#Data)do
local new = script.Cell:Clone()
new.Rarity.Value = Data[i].Rarity
new.name.Value = Data[i].Name
new.Parent = script.Parent.Main.Back
end
If you still got any problem don’t be shy to ask,I’ll always answer.