title: (Roblox) Why does my datastore not save data?
body: <p>I've been trying to create a custom inventory script, while making the server-side scripts, I've encountered a strange problem. Here's what happens when a player joins: A playeradded function in the server script fires, it then requests a datastore of the player's inventory from the module script. If the datastore loader encounters an error, it kicks the player to prevent overriding data. Otherwise, if no datastore exists, it creates a new list with 32 zeros. Now that it has a list of the player's inventory items, the server script tells the module script to store the inventory data in a list inside the module script. When a player is leaving, the server script requests the inventory data back and tells the module script to save it to datastore. Everything here seems to work fine apart from the actual datastore saving. I put a looped print function in the module.SetDataStore() function and it has the correct data. But when I load a new game, the datastore is still empty. What am I doing wrong here? (I have studio access to datastore enabled) Here's my code:</p>
  
  <p><strong>Regular script</strong></p>
  
  <pre><code>local module = require(script.Parent.ServerModule)
  local DataStoreService = game:GetService("DataStoreService")
  
  game.Players.PlayerAdded:Connect(function(plr)
      local plrdata = module.GetDataStore(plr.UserId.."-inventory")
      if plrdata then
          if plrdata == {} then
              plr:Kick("Failed to load data; please rejoin the game")
          end
      else
          plrdata = {}
          for i=1, 32 do
              print("Creating new data")
              plrdata[i] = 1
          end
      end
      module.SetPlayerData(plr.Name,plrdata)
      for i=1,32 do
          print(plrdata[i])
      end
  end)
  
  game.Players.PlayerRemoving:Connect(function(plr)
      local plrdata = module.GetPlayerData(plr.Name)
      module.SetDataStore(plr.UserId.."-inventory",plrdata)
  end)
  </code></pre>
  
  <p><strong>Module Script</strong></p>
  
  <pre><code>local DataStoreService = game:GetService("DataStoreService")
  local DataStore = DataStoreService:GetDataStore("MainDataStore")
  
  local plrdata = {}
  local module = {}
      function module.GetDataStore(datastoreid)
          local value
          local success, err = pcall(function()
              value = DataStore:GetAsync(datastoreid)
          end)
          if success then
              return value
          else
              warn(err)
              return {}
          end
      end
      function module.SetDataStore(datastoreid, value)
          for i=1, 32 do
              print(value[i])
          end
          local success, err = pcall(function()
              DataStore:SetAsync(datastoreid,value)
          end)
          if success then
              return true
          else        
              warn(err)
          end
      end
      function module.UpdateDataStore(datastoreid, value)
          local success, err = pcall(function()
              DataStore:UpdateAsync(datastoreid,value)
          end)
          if success then
              return true
          else
              warn(err)
          end
      end
      function module.RemoveDataStore(datastoreid)
          pcall(function()
              DataStore:RemoveAsync(datastoreid)
          end)
      end
      function module.SetPlayerData(id,newvalue)
          plrdata[id] = newvalue
      end
      function module.GetPlayerData(id)
          local data = plrdata[id]
          return data
      end
  return module
  </code></pre>