Tools datastore not saving upon PlayerRemoving?
Asked by
4 years ago Edited 4 years ago
Hello, so I've been trying to save upon playerremoving but it never wants to work. I even used BindToClose() and I know it works 30 seconds before shutdown they said. But when I leave, the tool wont save.
This is currently my code right now:
01 | local dataStoreService = game:GetService( "DataStoreService" ) |
02 | local dataStore = dataStoreService:GetDataStore( "BackpackSave" ) |
03 | game.Players.PlayerAdded:Connect( function (player) |
05 | local tool = dataStore:GetAsync( "User-" ..player.UserId) |
07 | for i,v in pairs (tool) do |
08 | local toolFound = game.ReplicatedStorage.Items:FindFirstChild(v) |
10 | toolFound:Clone().Parent = player.Backpack |
17 | game.Players.PlayerRemoving:Connect( function (player) |
21 | for i, tool in pairs (player.Backpack:GetChildren()) do |
23 | table.insert(toolsSave,tool.Name) |
26 | dataStore:SetAsync( "User-" ..player.UserId,toolsSave) |
30 | game:BindToClose( function () |
33 | for _, player in pairs (game.Players:GetPlayers()) do |
35 | for i, tool in pairs (player.Backpack:GetChildren()) do |
37 | table.insert(toolsSave,tool.Name) |
40 | dataStore:SetAsync( "User-" ..player.UserId,toolsSave) |
Any help is appreciated...