Roblox DataStore错误参数2丢失或为零

时间:2018-12-09 16:10:44

标签: datastore roblox

您好,我的Datastre总是遇到错误

获取ErreurArgument 2丢失或为零

我的代码在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 个答案:

答案 0 :(得分:1)

函数“ UpdateAsync”具有2个参数

  • 第一个,您要从数据存储中获取的
  • 第二个回调,一个功能,将被调用,接收到数据

该功能的正确用法是:

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)

有关更多信息,请参见Wiki的官方页面上有关“ UpdateAsync”功能的信息:https://developer.roblox.com/api-reference/function/GlobalDataStore/UpdateAsync