Okay so im trying to make a datastore for my game but its never saving, i have everything i need for a working datastore it just wont save heres my script
local DataStore = game:GetService("DataStoreService"):GetDataStore("DataStore1")
game.Players.PlayerAdded:Connect(function(plr)
local folder = Instance.new("Folder", plr)
folder.Name = "Inventory"
local success, errormsg = pcall(function()
local loaded = DataStore:GetAsync(plr.UserId)
if loaded then
for i, v in pairs(loaded)do
local x = Instance.new("IntValue", folder)
x.Name = v
end
end
end)
end)
function save(plr)
local saveTable = {}
for i, v in pairs(plr:WaitForChild("Inventory"):GetChildren())do
saveTable[#saveTable + 1] = v.Name
end
DataStore:UpdateAsync(plr.UserId, saveTable)
end
game:BindToClose(function()
if game:GetService("RunService"):IsStudio() then
for i, plr in pairs(game.Players:GetChildren())do
save(plr)
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
if not game:GetService("RunService"):IsStudio() then
save(plr)
end
end)