I'm making a custom inventory but it won't save! It says that it's saving but it's not. Here is the script.
local ds = game:GetService("DataStoreService"):GetDataStore("Inventory")
game.Players.PlayerAdded:Connect(function(p)
wait()
local inv = Instance.new("Folder",p)
inv.Name = "Inventory"
local success,fail = pcall(function()
local items = ds:GetAsync(p.UserId)
if items then
for i,v in pairs(items) do
if v then
if game.ReplicatedStorage.Items:FindFirstChild(v) then
game.ReplicatedStorage.Items[v.Name]:Clone().Parent = inv
end
end
end
end
end)
if success then
print("Got items!")
else
print("Didn't get items, possibly no items!")
end
end)
game.Players.PlayerRemoving:Connect(function(p)
local success,fail = pcall(function()
local itemstosave = {}
for i,v in pairs(p.Inventory:GetChildren()) do
if v then
table.insert(itemstosave,v.Name)
end
end
ds:SetAsync(p.UserId,itemstosave)
end)
if success then
print("Saved!")
else
print("Not Saved :(")
end
end)
