everytime i quit the game it print saved but when i join nothing saved . i dont see any error in the script
, can anyone tell me what is wrong? (I learned this from Alvin blox)
here is the item save script
local DataStoreService = game:GetService("DataStoreService")
local invenData = DataStoreService:GetDataStore("saveInven")
local ServerStorage = game:GetService("ServerStorage")
game.Players.PlayerAdded:Connect(function(Player)
local DataFolder = Instance.new("Folder")
DataFolder.Name = Player.Name
local inventory = Instance.new("Folder")
inventory.Name = "Inventory"
inventory.Parent = DataFolder
local backpack = Instance.new("Folder")
backpack.Name = "Backpack"
backpack.Parent = inventory
local equippedBackpack = Instance.new("StringValue")
equippedBackpack.Name = "EquippedBackpack"
equippedBackpack.Parent = inventory
DataFolder.Parent = ServerStorage.PlayersData
local backpackData
local equippedBackpackData
pcall(function()
backpackData = invenData:GetAsync(Player.UserId.."-Backpacks")
end)
pcall(function()
equippedBackpackData = invenData:GetAsync(Player.UserId.."-EquippedBackpackValue")
end)
if backpackData then
for _,Backpack in pairs(backpackData) do
if ServerStorage.Backpacks:FindFirstChild(Backpack) then
local backpackClone = ServerStorage.Backpacks[Backpack]:Clone()
backpackClone.Parent = backpack
print(Backpack.." loaded in!")
end
end
if equippedBackpackData then
equippedBackpack.Value = equippedBackpackData
local backpackClone = backpack:FindFirstChild(equippedBackpackData)
backpackClone.Name = "Backpack"
backpackClone.Parent = Player.Character
end
else
print("No backpacks data")
local starterbackpack = ServerStorage.Backpacks["Starter Backpack"]:Clone()
starterbackpack.Name = "Backpack"
starterbackpack.Parent = Player.Character
local itemValue = Instance.new("ObjectValue")
itemValue.Name = "Starter Backpack"
itemValue.Parent = backpack
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
pcall(function()
local backpacks = ServerStorage.PlayersData[Player.Name].Inventory.Backpacks:GetChildren()
local backpacksTable = {}
for _,v in pairs(backpacks) do
table.insert(backpacksTable,v.Name)
end
invenData:SetAsync(Player.UserId.."-Backpacks",backpacksTable)
if ServerStorage.PlayersData[Player.name].Inventory.EquippedBackpack.Value ~= nil then
local EquippedBackpack = ServerStorage.PlayersData[Player.Name].Inventory.EquippedBackpack
invenData:SetAsync(Player.UserId.."-EquippedBackpackValue",EquippedBackpack.Value)
end
end)
print("Saved backpacks")
end)