Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

I need help with my Items Script. Attempt to index nil with "Items"?

Asked by 7 days ago
Edited by JesseSong 7 days ago

Please encode Lua code in the Lua block code tag (look for the Lua icon in the editor).

Description:

I use this RemoteFunction to access data through localscripts, when its called its erroring too.

If you need more information tell me. Thanks

Error(s):

Attempt to index nil with 'Items' in the function :Get()

Error line:

return ItemData[player.UserId].Items.

remotes.GetItems.OnServerInvoke = function(player)
    return dataitem:get(player)
end

Main Code:

local pdata = {
        Items = {
            Item1 = {
                Name = "Paper Hat",
                Own = 0,
                Value = 600,
                Id = 10476359,
                Locked = false,
            },
            Item2 = {
                Name = "Know-It-All Grin",
                Own = 0,
                Value = 1400,
                Id = 26424808,
                Locked = false,
            },
            Item3 = {
                Name = "Canadian Toque",
                Own = 0,
                Value = 1700,
                Id = 122277006,
                Locked = false,
            },
            Item4 = {
                Name = "Slickfang",
                Own = 0,
                Value = 2400,
                Id = 7317765,
                Locked = false,
            },
            Item5 = {
                Name = "Mint Ice Cream Hair",
                Own = 0,
                Value = 4574,
                Id = 553892446,
                Locked = false,
            },
            Item6 = {
                Name = "Mint Flower Princess Hair",
                Own = 0,
                Value = 6487,
                Id = 280658726,
                Locked = false,
            },
            Item7 = {
                Name = "Mint Cow Hood",
                Own = 0,
                Value = 9333,
                Id = 5506204338,
                Locked = false,
            },
            Item8 = {
                Name = "Back Kite: Mint Maze",
                Own = 0,
                Value = 10198,
                Id = 5031630104,
                Locked = false,
            },
            Item9 = {
                Name = "Valkyrie Helm",
                Own = 0,
                Value = 200000,
                Id = 1365767,
                Locked = false,
            },
            Item10 = {
                Name = "White Sparkle Time Fedora",
                Own = 0,
                Value = 275000,
                Id = 1016143686,
                Locked = false,
            },
            Item11 = {
                Name = "Doge",
                Own = 0,
                Value = 350000,
                Id = 151784320,
                Locked = false,
            },
            Item12 = {
                Name = "Dominus Rex",
                Own = 0,
                Value = 400000, --1/100 chance
                Id = 250395631,
                Locked = false,
            },
            Item13 = {
                Name = "Cherry Bun with Waves",
                Own = 0,
                Value = 11998,
                Id = 4124398247,
                Locked = false,
            },
            Item14 = {
                Name = "Cherry Tree Battle Axe",
                Own = 0,
                Value = 14500,
                Id = 2830512657,
                Locked = false,
            },
            Item15 = {
                Name = "Cherry Ombre Space Bun Braid",
                Own = 0,
                Value = 19000,
                Id = 4614107854,
                Locked = false,
            },
            Item16 = {
                Name = "Cherry Stunning Glasses",
                Own = 0,
                Value = 20459,
                Id = 5518358345,
                Locked = false,
            },
            Item17 = {
                Name = "Cherry Cream Cupcake",
                Own = 0,
                Value = 26168,
                Id = 4585213421,
                Locked = false,
            },
            Item18 = {
                Name = "Cherry Bunny Ears",
                Own = 0,
                Value = 27000,
                Id = 3757152460,
                Locked = false,
            },
            Item19 = {
                Name = "Cherry Earrings",
                Own = 0,
                Value = 29899,
                Id = 4659750955,
                Locked = false,
            },
            Item20 = {
                Name = "Wild Rainbow Gem Top Hat",
                Own = 0,
                Value = 37000,
                Id = 1416402608,
                Locked = false,
            },
            Item21 = {
                Name = "Rainbow Fedora",
                Own = 0,
                Value = 41988,
                Id = 82332012,
                Locked = false,
            },
            Item22 = {
                Name = "Rainbow Cranbow",
                Own = 0,
                Value = 44999,
                Id = 43597614,
                Locked = false,
            },
            Item23 = {
                Name = "Rainbow Bowtie",
                Own = 0,
                Value = 48299,
                Id = 187846647,
                Locked = false,
            },
            Item24 = {
                Name = "Double Rainbow",
                Own = 0,
                Value = 52149,
                Id = 35246042,
                Locked = false,
            },
            Item25 = {
                Name = "Rainbow Pixels Bandana",
                Own = 0,
                Value = 55899,
                Id = 3267569146,
                Locked = false,
            },
            Item26 = {
                Name = "Frobow The Sad Clown",
                Own = 0,
                Value = 60349,
                Id = 11721197,
                Locked = false,
            },
            Item27 = {
                Name = "Rainbow Hatbot",
                Own = 0,
                Value = 62000,
                Id = 149594188,
                Locked = false,
            },
            Item28 = {
                Name = "Omega Rainbow Horns",
                Own = 0,
                Value = 64448,
                Id = 1241205162,
                Locked = false,
            },
            Item29 = {
                Name = "Rainbow Vision Shutter Shades",
                Own = 0,
                Value = 68000,
                Id = 556821882,
                Locked = false,
            },
            Item30 = {
                Name = "8-Bit Rainbow Shades",
                Own = 0,
                Value = 72000,
                Id = 2830371616,
                Locked = false,
            },
            Item31 = {
                Name = "White Pumpkin",
                Own = 0,
                Value = 400000,
                Id = 5700497578,
                Locked = false,
            },
            Item32 = {
                Name = "Orange Top Hat",
                Own = 0,
                Value = 400000,
                Id = 5700485638,
                Locked = false,
            },
            Item33 = {
                Name = "Pumpkin Face",
                Own = 0,
                Value = 400000,
                Id = 313549781,
                Locked = false,
            },
            Item34 = {
                Name = "Orange Fedora",
                Own = 0,
                Value = 400000,
                Id = 5727740590,
                Locked = false,
            },
            Item35 = {
                Name = "Halloween Hood",
                Own = 0,
                Value = 400000,
                Id = 5699788515,
                Locked = false,
            },
            Item36 = {
                Name = "Shattered Minions (Back)",
                Own = 0,
                Value = 400000,
                Id = 5410522380,
                Locked = false,
            },
            Item37 = {
                Name = "Halloween Balloons",
                Own = 0,
                Value = 400000,
                Id = 5806414021,
                Locked = false,
            },
            Item38 = {
                Name = "Pumpkin Headrow",
                Own = 0,
                Value = 400000,
                Id = 95245137,
                Locked = false,
            },
            Item39 = {
                Name = "Skeleton Arms",
                Own = 0,
                Value = 400000,
                Id = 5803345882,
                Locked = false,
            },
            Item40 = {
                Name = "Halloween Horns",
                Own = 0,
                Value = 400000,
                Id = 5700904808,
                Locked = false,
            },
            Item41 = {
                Name = "Shattered Minions",
                Own = 0,
                Value = 500000,
                Id = 5410521239,
                Locked = false,
            },
            Item42 = {
                Name = "Halloween Bandana",
                Own = 0,
                Value = 500000,
                Id = 5699767775,
                Locked = false,
            },
            Item43 = {
                Name = "Halloween Head",
                Own = 0,
                Value = 500000,
                Id = 5699778651,
                Locked = false,
            },
            Item44 = {
                Name = "Pumpkin Patch",
                Own = 0,
                Value = 500000,
                Id = 5728733523,
                Locked = false,
            },
            Item45 = {
                Name = "Halloween Antlers",
                Own = 0,
                Value = 500000,
                Id = 5802982831,
                Locked = false,
            },
            Item46 = {
                Name = "Skeleton Minions",
                Own = 0,
                Value = 500000,
                Id = 5728865570,
                Locked = false,
            },
            Item47 = {
                Name = "Hollow Demon Mask",
                Own = 0,
                Value = 500000,
                Id = 5764204182,
                Locked = false,
            },
            Item48 = {
                Name = "Shoulder Pumpkins",
                Own = 0,
                Value = 500000,
                Id = 5700364514,
                Locked = false,
            },
            Item49 = {
                Name = "Spooky Time Fedora",
                Own = 0,
                Value = 500000,
                Id = 4090366145,
                Locked = false,
            },
            Item50 = {
                Name = "Pumpkin Dominus",
                Own = 0,
                Value = 500000,
                Id = 400741840,
                Locked = false,
            },
            Item51 = {
                Name = "Midnight Motor Magnifique",
                Own = 0,
                Value = 1300000,
                Id = 456225312,
                Locked = false,
            },
            Item52 = {
                Name = "Pink Droplet",
                Own = 0,
                Value = 1800000,
                Id = 3712340786,
                Locked = false,
            },
            Item53 = {
                Name = "Furry Animal Hoodie",
                Own = 0,
                Value = 2500000,
                Id = 3663697414,
                Locked = false,
            },
            Item54 = {
                Name = "Strawberry Cow Hood",
                Own = 0,
                Value = 3200000,
                Id = 5355719986,
                Locked = false,
            },
            Item55 = {
                Name = "Monster Smile",
                Own = 0,
                Value = 3600000,
                Id = 398675917,
                Locked = false,
            },
            Item56 = {
                Name = "Giant ?? Heart ?? Bear",
                Own = 0,
                Value = 4000000,
                Id = 5460035827,
                Locked = false,
            },
            Item57 = {
                Name = "Banana Cow Hood",
                Own = 0,
                Value = 5000000,
                Id = 5460102502,
                Locked = false,
            },
            Item58 = {
                Name = "Mr Tentacles",
                Own = 0,
                Value = 7000000,
                Id = 11188696,
                Locked = false,
            },
            Item59 = {
                Name = "Cartoony Rainbow Banded Top Hat",
                Own = 0,
                Value = 10000000,
                Id = 5275861024,
                Locked = false,
            },
            Item60 = {
                Name = "Cousin Tentacles",
                Own = 0,
                Value = 50000000,
                Id = 271014536,
                Locked = false,
            },
        },
    };


    if not GameData:GetAsync(player.UserId) then
        ItemData[player.UserId] = pdata
    else
        local playerdata = GameData:GetAsync(player)
        ItemData[player.UserId] = playerdata
    end

    return ItemData[player.UserId].Items
end

function MetaData:Save(player)
    if ItemData[player.UserId] then
        GameData:SetAsync(player.UserId, ItemData[player.UserId])
    end
end


function MetaData:get(player)
    return ItemData[player.UserId].Items
end

function MetaData:remove(player)
    MetaData:Save(player)

    ItemData[player.UserId] = nil
end

--// Enchanted \\--
return setmetatable(ItemData, MetaData);

Re-edited by JesseSong!

0
Encode your code properly by using a code block. JesseSong 3372 — 7d
0
it means ItemData does not have that specific player in it's table TTChaos 731 — 7d

1 answer

Log in to vote
0
Answered by 7 days ago

You placed dot in

return ItemData[player.UserId].Items.

This code should work for you

return ItemData[player.UserId].Items

remotes.GetItems.OnServerInvoke = function(player)
    return dataitem:get(player)
end
Ad

Answer this question