Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Table calling error?

Asked by
Decemus 141
8 years ago

I have a few tables inside a table, and a table above that. Whenever I attempt to run this script, this error prints out,'Players.Player1.PlayerGui.ShopGUI.Main.MainScript:38: attempt to index field '?' (a nil value)' I have tried tweaking it a bit, and have run a test before and it worked. Please explain to me why it did not work, and attempt to solve the issue for me. Tables:

local Itemnames = {"Part","Test2","Test","ff"}
local Items = {
    ["Part"] = {
        ["Name"] = "Part",
        ["Price"] = 100, 
        ["Description"] = "DESCRIPTION HERE",
        ["Level Requirement"] = 2
    }
    ,["Test2"] = {
        ["Name"] = "Sabre",
        ["Price"] = 201, 
        ["Description"] = "DESCRIPTION HERE TEST",
        ["Level Requirement"] = 55
    }
        ,["Test"] = {
        ["Name"] = "Test",
        ["Price"] = 2431, 
        ["Description"] = "Test",
        ["Level Requirement"] = 7
        }
        ,["ff"] = {
        ["Name"] = "ff",
        ["Price"] = 2000, 
        ["Description"] = "Test Description",
        ["Level Requirement"] = 5
    }
}

Part of script where the error is appearing:

for i=1,(#Itemnames) do
    local currentItem = (Itemnames[i])
    Itm = script.Item:Clone()
    local pos = 0
    Itm.Parent = script.Parent.Itemlist
    Itm.Position = UDim2.new(0,0,0,pos)
    Itm.Namef.Text = (Itemnames[i])
    Itm.Price.Text = (Items[currentItem]["Price"])-- The error is appearing here
    pos = pos + 26
    end

Answer this question