local service = game:GetService("DataStoreService") local datastore = service:GetDataStore("hleol") game.Players.PlayerAdded:Connect(function(Player) if datastore:GetAsync(Player.userId) then for i, v in pairs(datastore:GetAsync(Player.userId)) do print(v) local tool = game.ServerStorage[v]:Clone() tool.Parent = Player.Backpack end end end) game.Players.PlayerRemoving:Connect(function(Player) local ToolsToSave = { } for i, v in pairs(Player.Backpack:GetChildren()) do table.insert(ToolsToSave, v.Name) end print("a") datastore:SetAsync(Player.userId, ToolsToSave) end)
At line 9, it does not parent it to the backpack. I tried with workspace, and it worked. But backpack seem to not be broken. Any fix?
local service = game:GetService("DataStoreService") local datastore = service:GetDataStore("hleol") game.Players.PlayerAdded:Connect(function(Player) if datastore:GetAsync(Player.UserId) then for i, v in pairs(datastore:GetAsync(Player.userId)) do print(v) Player.CharacterAdded:Connect(function() local tool = game.ServerStorage[v]:Clone() tool.Parent = Player.Backpack end) end end end) game.Players.PlayerRemoving:Connect(function(Player) local ToolsToSave = { } for i, v in pairs(Player.Backpack:GetChildren()) do table.insert(ToolsToSave, v.Name) end print("a") datastore:SetAsync(Player.UserId, ToolsToSave) end)
this will wait for the character and then clone the tool, this needs to be done since when the character gets added the players backpack gets deleted