Hello, I'm making a shop system that places itself onto a gui but its not listed as it should be seen on the "ShopList" table. For example it prints out Shotgun, Pistol and then Raygun where it should actually say Pistol, Shotgun and then Raygun. I don't know any solutions..
local ShopList = { ['Pistol'] = {Image = "rbxassestid://00000"}, ['Shotgun'] = { Image = "rbxassestid://00000"}, ['Raygun'] = {Image = "rbxassestid://00000"}, } for Table,Info in pairs(ShopList) do print(Table) print('Loaded '.. Table..' Shop item') end
Dictionaries cannot be organized in a certain order. If you want it to do that you could either create a table in which you print it in the order you'd like:
local shopList = { ['g1'] = '12344' ['g2'] = '44321' } local order = {'g1', 'g2'} for i,v in pairs(order) do print(shopList[v]) end
or you can not use table.sort, except you'd have to format your table differently.
local shopList = { {'g1', 'asset/1234', 1} {'g2', 'asset/4321', 2} } table.sort(shopList, function(a,b) return a[3] > b[3] end) for i,v in pairs(shopList) do local itemName = v[1] local assetId = v[2] local order = v[3] end