Problem with shop system

So i started with a shop system using a table, but it seems like something went wrong and it’s probably with the table, because i don’t have any errors and also any experience with tables xd.

Here’s my code:

local BG = script.Parent.BG
local PickaxesGrid = BG.PickaxesFrame.GRID
local InfoFrame = BG.InfoFrame
local ItemName = InfoFrame.ItemName
local ItemPrice = InfoFrame.Price
local ItemDmg = InfoFrame.StatsFrame.Dmg
local BuyButton = InfoFrame.BuyFrame.BUY

local Pickaxes = {
	DirtPickaxe =  {
		["Name"] = "Dirt Pickaxe";
		["Damage"] = 1;
		["Price"] = 100;
		["Path"] = game.ReplicatedStorage.Pickaxes["Dirt Pickaxe"];
		["Owned"] = false;
	WoodenPickaxe =  {
		["Name"] = "Wooden Pickaxe";
		["Damage"] = 2;
		["Price"] = 250;
		["Path"] = game.ReplicatedStorage.Pickaxes["Wooden Pickaxe"];
		["Owned"] = false;
		}
	}

	}



for _, button in pairs(PickaxesGrid:GetChildren()) do
	if button:IsA("ImageButton") then
		button.MouseButton1Click:Connect(function()
			if button.Name == Pickaxes.DirtPickaxe.Name then
				ItemName.Text = Pickaxes.DirtPickaxe.Name
				ItemPrice.Text = "Price : "..Pickaxes.DirtPickaxe.Price.."$"
				ItemDmg.Text = "Dmg.: "..Pickaxes.DirtPickaxe.Damage
			end
		end)
	end
end
1 Like

Are there any errors? Can you describe the problem in any more detail?

1 Like

there’s a syntax issue in your Pickaxes table. you have a missing closing bracket for the DirtPickaxe table,

local Pickaxes = {
    DirtPickaxe =  {
        ["Name"] = "Dirt Pickaxe",
        ["Damage"] = 1,
        ["Price"] = 100,
        ["Path"] = game.ReplicatedStorage.Pickaxes["Dirt Pickaxe"],
        ["Owned"] = false
    }, -- Missing comma here and closing bracket was missing
    WoodenPickaxe =  {
        ["Name"] = "Wooden Pickaxe",
        ["Damage"] = 2,
        ["Price"] = 250,
        ["Path"] = game.ReplicatedStorage.Pickaxes["Wooden Pickaxe"],
        ["Owned"] = false
    }
}

for _, button in pairs(PickaxesGrid:GetChildren()) do
    if button:IsA("ImageButton") then
        button.MouseButton1Click:Connect(function()
            for pickaxeName, pickaxeInfo in pairs(Pickaxes) do
                if button.Name == pickaxeInfo.Name then
                    ItemName.Text = pickaxeInfo.Name
                    ItemPrice.Text = "Price : "..pickaxeInfo.Price.."$"
                    ItemDmg.Text = "Dmg.: "..pickaxeInfo.Damage
                    break 
                end
            end
        end)
    end
end

6 Likes

A table is just a collection of stuff. Every element in the table has a key and a value. Tables can either be ‘arrays’, which means all the keys are numbers counting up (so the key for the first element is 1, second element is 2, etc), or tables can be ‘dictionaries’. A dictionary means you set the key yourself, to anything you want (for example a string). You have a dictionary, because your keys are strings (‘DirtPickaxe’, for example).

Between every element in a table, we need to add commas. To get the value of an element in a table, we use table[key].

local myArray = {
  'Hello!',
  'How are you?',
  'Nice weather today!'
}

print(myArray[1]) -- prints 'Hello!'
print(myArray[2]) -- prints 'How are you?'
print(myArray[3]) -- prints 'Nice weather today!'

local myDictionary = {
  FirstMessage='Hello!', 
  SecondMessage='How are you?',
  ThirdMessage='Nice weather today!'
}


print(myDictionary[FirstMessage]) -- prints 'Hello!'
print(myDictionary[SecondMessage]) -- prints 'How are you?'
print(myDictionary[ThirdMessage]) -- prints 'Nice weather today!'

So the array is kind of like this, which means to get the value of an element, we just use the key (which is the index) myTable[index]

local myArray = {
  [1]= 'Hello!',
  [2]='How are you?',
  [3]='Nice weather today!'
}

We can have tables as elements of tables, but we always need to close the table ( start={, end=} ), and between elements we have commas.

local myDictionary= {
  colorsThatIEnjoy = {'Cyan', 'Orange', 'Black'},
  myFavouriteHolidays = {'St Nicholas', 'New years eve'}
}

Thank you so much! I was so confused because there werent any output errors or any sign what could be wrong. Thanks!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.