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

Roblox DataStore Error argument 2 missing or nil

你好,我的 Datastre 总是获取错误

获取 ErreurArgument 2 missing or nil

我的代码在 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

函数"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