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