【问题标题】:Roblox DataStore Error argument 2 missing or nilRoblox 数据存储错误参数 2 丢失或为零
【发布时间】:2019-05-10 16:11:51
【问题描述】:

您好,我的 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

【问题讨论】:

  • 不清楚你在问什么。请在发布问题之前阅读此内容:stackoverflow.com/help/how-to-ask
  • (为了邮件的可读性,在邮件标签后面添加一个空格,如'Erreur '..err。)
  • 好的,下次我读来问问题,所以我的问题很简单,希望在错误时留出空间希望任何人都可以回答我的问题,哈哈,我现在在这个脚本上的错误是什么 Erreur Argument 2 missing或无

标签: datastore roblox


【解决方案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

【讨论】:

  • 好的!可以用表写变量数据吗?
猜你喜欢
  • 2020-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-07
  • 2018-07-14
  • 2020-09-20
  • 2016-01-07
相关资源
最近更新 更多