This script is supposed to create a frame for each skin from a table although when testing it just clones the same skin into a frame for the amount of skins there are in the table. Any help is appreciated.
Gui:
function CreateFrame(List)
for index, Skin in pairs(List) do
local Frame = Template:Clone()
Frame.Name = Skin.Name
Frame.Title.Text = Skin.Name
Frame.Image = Skin.Image
Frame.Cost.Text = "Ashes "..Skin.Cost
Frame.Parent = Skins
return Frame
end
end
local SkinsList = require(SkinsFolder:WaitForChild("SkinsList"))
function CreateSkins(Data)
for i, v in pairs(Data) do
local Frame = CreateFrame(Data)
end
end
SendData.OnClientEvent:Connect(function()
CreateSkins(SkinsList)
end)
I’m my experience, looping through dictionaries is a tricky business. I found a topic that gave me a getKeys() function, that you can plug in to your table loop.
local function getKeys(t)
local keys = {}
for k in next, t do
table.insert(keys, k)
end
table.sort(keys)
return keys
end
If you use that function it should solve your problem
Alright so I changed the ipairs to pairs and now it’s creating the frames for the amount of skins in the table, but it’s just the same thing over and over again.
There’s other stuff in the CreateSkins function that I’ve removed to keep this post simple, I’ve found that it’s passing the entire table in the CreateFrame function instead of just parts which is causing the issue, how could I make this edit?
local function CreateFrames()
for i,skin in pairs(SkinList) do
local Frame = Template:Clone()
Frame.Name = Skin.Name
Frame.Title.Text = Skin.Name
Frame.Image = Skin.Image
Frame.Cost.Text = "Ashes "..Skin.Cost
Frame.Parent = Skins
end
end
That should be all you need. No CreateSkins function necessary.