Why does DataStore:GetAsync return an empty table / nil value every time?
First, my code:
01 | local DATASTORESERVICE = game:GetService( "DataStoreService" ) |
02 | local toolStore = DATASTORESERVICE:GetDataStore( "-tools" ) |
03 | game.Players.PlayerRemoving:Connect( function (player) |
06 | for _,v in pairs (player.Backpack:GetChildren()) do |
07 | table.insert(tools, 1 ,v) |
08 | print ( "Saving: " ..v.Name) |
10 | for _,v in pairs (player.Character:GetChildren()) do |
12 | table.insert(tools, 1 ,v) |
13 | print ( "Saving: " ..v.Name) |
18 | for i,v in pairs (game.ServerStorage:GetChildren()) do |
19 | if tools:FindFirstChild(v.Name) then |
20 | table.insert(own,i, true ) |
22 | table.insert(own,i, false ) |
25 | toolStore:SetAsync( "-tools" ..player.UserId,own) |
29 | game.Players.PlayerAdded:Connect( function (player) |
30 | local success,value = pcall ( function () |
31 | local tools = toolStore:GetAsync( "-tools" ..player.UserId) |
35 | for i,v in pairs (own) do |
37 | local tool = game.ServerStorage:GetChildren() [ i ] :Clone() |
38 | tool.Parent = player.Backpack |
This is all 1 script. I am trying to store which weapons a user leaves the game with, so that when they re-enter the game, they have those same weapons.
Currently, it seems to save just fine. I have tried saving a string, and it ends up returning an empty table when I use GetAsync.
Why does this not work, or what would I need to do to make this work?
If you have any further questions, please ask them. I really need to get this fixed.