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

Sub-Table data doesn't load, invalid arguement #1 to 'ipairs'?

Asked by 3 years ago

Ok so, I'm making a mining simulator, and I want to make a tool DataStore. For some reason, the data won't load properly.

Script I used:

001local DataStoreService = game:GetService("DataStoreService")
002local DS = DataStoreService:GetDataStore("MinerzData")
003 
004local function loadData(player)
005    local key = player.UserId .. "-minerzData"
006    local data
007 
008    local success,errorMessage = pcall(function()
009        data = DS:GetAsync(key)
010    end)
011 
012    if success then
013        print('MinerzData | Successfully loaded ' .. player.Name .. "'s data!")
014        return data
015    elseif errorMessage then
View all 104 lines...

On line 78, it errors with:

1ServerScriptService.InventoryHandler:79: invalid argument #1 to 'ipairs' (table expected, got nil)

On line 23 I define the "data" table in the saveData() function. I also define "pickaxes" as a sub-table. (line 27) For some reason, when I join the game, it says table expected, got nil. I don't know why this happens, and when I do a print(data.pickaxes), it just prints "nil."

If someone could help, it would mean a lot to me!

Answer this question