Hi, I have a datastore that should save the inventory when a player leaves and load it back in again after joining but it is not working. Can someone please help. Thank you
Script in ServerScriptService:
local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("InventorySaveSystem")
local RE = game.Workspace.ItemSave
local function PlayerJoin(player)
pcall(function()
local tool = DataStore:GetAsync("User-".. player.UserId)
if tool then
for i,v in pairs(tool) do
print(v)
local toolFound = game.ReplicatedStorage.Items:FindFirstChild(v)
if toolFound then
toolFound:Clone().Parent = player.Backpack
toolFound:Clone().Parent = player.StarterGear
end
end
end
end)
end
local function SaveItem(player)
pcall(function()
local toolsSave = {}
for i, tool in pairs(player.Backpack:GetChildren()) do
if tool then
table.insert(toolsSave,tool.Name)
end
end
ds:SetAsync("User-".. player.UserId,toolsSave)
end)
end
game.Players.PlayerAdded:Connect(PlayerJoin)
game.Players.PlayerRemoving:Connect(SaveItem)
