Struggling to access data store variable?
I'm trying to write a pretty basic inventory store system. At the moment it takes all the items from the player's inventory folder, stores the names of the items in a table and saves them (when the player leaves). However, when trying to print the data the error I get is:
ServerScriptService.InventorySaveScript:31: bad argument #1 to 'ipairs' (table expected, got nil) This error is caused on line 05.
If you're trying to interpret the script, start with the player removing function.
01 | function saveInventory(inventoryData,player,savedData) |
02 | inventoryDataStore:SetAsync(player.UserId,inventoryData) |
03 | savedData = inventoryDataStore:GetAsync(player.userId) |
05 | for i, v in ipairs (savedData.inventoryData) do |
10 | function fillTable(player,inventoryData) |
12 | print ( "--------------" ) |
13 | inventoryContent = player.inventory.inventoryItemFolder:GetChildren() |
15 | for i, child in ipairs (inventoryContent) do |
16 | table.insert(inventoryData, i, child.Name) |
19 | if inventoryData ~ = nil then |
20 | for i, v in ipairs (inventoryData) do |
25 | saveInventory(inventoryData,player) |
29 | game.Players.PlayerRemoving:Connect( function (player) |
30 | fillTable(player,inventoryData) |