So, this is my datastore script so far, however for some reason, it's attempting to call a nil value. Here's my script:
local DS = game:GetService("DataStoreService"):GetDataStore("Inventories")
game.Players.PlayerAdded:Connect(function(player)
variablePlayer = player.Name
local folder = Instance.new("Folder",player)
folder.Name = "inventory"
inventory = {}
inventory.Name = "inventory"
local dataKey = "userkey_"..player.UserId
local data
local success,errormsg = pcall(function()
data = DS:GetAsync(dataKey)
end)
if not success then
warn("Error when retrieving data for "..player.Name..". Error: "..errormsg)
folder.Value = nil
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success,errormsg = pcall(function()
for i, v in pairs(game.Players[variablePlayer].inventory:GetChildren()) do
inventory.insert(v.Value) -- This is where the error is.
print(v.Value)
end
DS:SetAsync("userkey_"..player.UserId, inventory)
end)
if not success then
warn("Unable to save for "..player.Name..". Error: "..errormsg)
end
end)
Error message:
Unable to save for 7z99. Error: ServerScriptService.inventory:21: attempt to call a nil value

2 comments
Wouldn't you type table.insert(inventory, v.Value)?
You're right. Thanks! The script isn't entirely working though. I'll edit since it brought up new problems.