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.
function saveInventory(inventoryData,player,savedData)
inventoryDataStore:SetAsync(player.UserId,inventoryData)
savedData = inventoryDataStore:GetAsync(player.userId)
print(savedData)
for i, v in ipairs(savedData.inventoryData) do
print(v)
end
end
function fillTable(player,inventoryData)
print("--------------")
inventoryContent = player.inventory.inventoryItemFolder:GetChildren()
for i, child in ipairs(inventoryContent) do
table.insert(inventoryData, i, child.Name)
end
if inventoryData ~= nil then
for i, v in ipairs(inventoryData) do
print(v)
end
end
saveInventory(inventoryData,player)
end
game.Players.PlayerRemoving:Connect(function(player)
fillTable(player,inventoryData)
end)
