Getting next item from module

Hi! I’m making a shop system (Like saber simulator, ninja legends etc) and I’ve ran into a problem with getting the next item after the selected.

Script

function Shop:SetDescription()
	for _, v in pairs(script.Parent.Parent.Shop.ShopItems.ScrollingFrame:GetChildren()) do
		if v:IsA("ImageLabel") then		
			v.Top.Button.MouseButton1Click:Connect(function()
				self:ResetVp(Info.VP)
				self:SetVP(Info.VP, v.Name)
				Info.ItemName.Text = v.Name
				Info.Price.Text = Config[v.Name].Price
				Info.Boost.Text = Config[v.Name].Boost
				
				for _,test in pairs(Config) do
					if test.Sort == Config[v.Name].Sort+1 then
						print(test)
					end
				end
			end)
		end
	end
end

Config

local Config = {
	["Item1"] = {
		Price = 100,
		Boost = 1,
		Sort = 1,
		Locked = false,
	},
	
	["Item2"] = {
		Price = 150,
		Boost = 2,
		Sort = 2,
		Locked = true,
	},

	["Item3"] = {
		Price = 300,
		Boost = 4,
		Sort = 3,
		Locked = true,
	},
}

return Config

There aren’t any errors but I can’t seem to get the item2 string when item1 is selected but what i get is the price, boost, sort, locked

I’m using this system to get the next item and check if its locked to unlock it when user buys the item.

If you need more info just reply to the post.

Thanks.

Where are you trying to get the next item? Can you do this?
Config["Item"..tostring(Config[v.Name].Sort+1)]

Im trying to get the next item, but the items wont be called with number at the end so that wont really work ill later call them like sword etc

Solved lol i just had to do for i,test in pairs instead of for _, test cause i returns the name

1 Like