0
votes

Hello have probleme this my Datastre obtain error always time

obtain ErreurArgument 2 missing or nil

my code is on pastbin https://pastebin.com/tPvBtHuR

local succes , err = pcall(function() -- Pcall
    local key = ("user_" .. Player.userId)
     local Data = PlayerData:UpdateAsync(key)
        if Data == nil then
            Data = DefaultData
        end
        PlayerData:SetAsync(key) -- Save
end)
if succes then 
    print ('Succes'..succes)
end

if err then 
    print ('Erreur'..err)
end

end
1
It is unclear what you are asking. Please read this before posting questions: stackoverflow.com/help/how-to-ask - Dezso Gabos
(For message readability, add a trailing space to the message labels as in 'Erreur '..err.) - greybeard
Ok next time im read to ask question so my question is simpli want juste to ty for space on error want any can respond to my question lol what is my error on this script got now Erreur Argument 2 missing or nil - ShadowOffice

1 Answers

1
votes

The function "UpdateAsync" has 2 argument

  • first one, the key you want to get from the datastore
  • second one, the callback, a function that will be called the data is received

The correct usage of the function is:

local succes , err = pcall(function() -- Pcall
  local key = ("user_" .. Player.userId)
  PlayerData:UpdateAsync(key, function(Data)
      -- Here you have the data (from the variable Data)

      -- Short example
      print(Data) -- Will return your Data

      -- if it's a number like a score, you can just increase it and export it to the datastore directly
      return Data + 50

      -- In the case you just want to get the data, just place a return Data
      return Data
  end)
end)

For more information, please refer to the official page of the wiki about the function "UpdateAsync": https://developer.roblox.com/api-reference/function/GlobalDataStore/UpdateAsync