【问题标题】:Saving Player Data in RLua在 RLua 中保存玩家数据
【发布时间】:2016-09-10 19:30:32
【问题描述】:

这些不起作用有什么原因吗?

玩家加入脚本:

local DataStore = game:GetService("DataStoreService"):GetDataStore("GeneralStats")


game.Players.PlayerAdded:connect(function(player)

    local stats = Instance.new("IntValue", player)
    stats.Name = "leaderstats"

    local points = Instance.new("IntValue", stats)
    points.Name = "Points"

    local credits = Instance.new("IntValue", stats)
    credits.Name = "Credits"    

    local key = "player-"..player.userId

    local savedValues = DataStore:GetAsync(key)

    if savedValues then
        --Save format: (points, credits)
        points.Value = savedValues[1]
        credits.Value = savedValues[2]
    else
        local ValuesToSave = {points.Value, credits.Value}
        DataStore:SetAsync(key, ValuesToSave)
    end


end)

还有这个玩家离开时的其他脚本。

local DataStore = game:GetService("DataStoreService"):GetDataStore("GeneralStats")

game.Players.PlayerRemoving:connect(function(player)

    local key = "player-"..player.userId    

    --Save key: {points, credits}
    local valuesToSave = {player.leaderstats.Points.Values, player.leaderstats.Credits.Values}
    DataStore:SetAsync(key, valuesToSave)

end)

这是我正在开发的一款游戏,请证明(RLuaRoblox Lua,如果你不知道的话)。

【问题讨论】:

  • 您能分享一下您希望代码做什么以及它会做什么吗?
  • 试图澄清。修正语法

标签: lua roblox


【解决方案1】:

是的,在您有机会提取数据之前,leaderstat 很可能已被删除。

我建议不要使用 leaderstats 作为数据参考。最好直接在脚本上存储数据。

但是,如果您确实必须使用 leaderstats,请将其作为父对象,提取数据,然后将其删除。

local lead = player.leaderstats
lead.Parent = game
-- extract data
lead:Destroy()

或者你可以在它们被重新定义之前在一个变量中定义所有这些对象。

但同样,我强烈建议不要使用 leaderstats 来保存数据。漏洞利用者可以轻松更改该数据并将值更改为较高的数字。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-14
    • 2014-06-29
    • 1970-01-01
    • 2020-05-01
    • 2018-07-28
    • 1970-01-01
    • 1970-01-01
    • 2016-01-06
    相关资源
    最近更新 更多