Hello! Here's my datastore script so far. There are no errors, but nothing appears to save or load. All that happens when a user joins the game is a new IntValue with the value 0. When the player leaves, the values are still printed, however using a datastore editor displays no data in the Inventories datastore.
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 success then
for i,v in pairs(data) do
local i2 = Instance.new("IntValue", folder)
i2.Value = v
end
else
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
table.insert(inventory, v.Value)
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)

2 comments
put: while nil do break end that will fix it
Where?