【问题标题】:Attempt to index nil with 'Value' While saving Error在保存错误时尝试使用“值”索引 nil
【发布时间】:2021-02-18 09:22:35
【问题描述】:

所以我试图保存 3 件东西,但即使在打印值时它有效,它也无法在保存脚本中索引它们:

game.Players.PlayerRemoving:Connect(function(player)
    local stats = player:FindFirstChild(ns0)
    if not stats then return end
    local vals = {stats:FindFirstChild(nc0),stats:FindFirstChild(nc1),stats:FindFirstChild(nc2)}
    print(vals) -- returns: {...}
    print(vals[1], vals[2], vals[3]) -- returns: Cash NumberValue dropspeed
    print(vals[1].Value, vals[2].Value, vals[3].Value) -- returns: 0.1 0.02 9.5
    print(player.UserId) -- returns my user Id
    --if vals and vals[1] and vals[2] and vals[3] then
    if vals[1] and vals[2] and vals[3] then
        ds:SetAsync(player.UserId,{vals[0].Value, vals[1].Value, vals[2].Value}) -- attempt to index nil with Value error occurs here
    end
end)

有什么问题?

【问题讨论】:

  • vals[0]nil

标签: lua roblox


【解决方案1】:

vals[0] 被索引为 nil,所以我将 vals[0] 更改为 vals[1],将 vals[1] 更改为 vals[2] 等

【讨论】:

    猜你喜欢
    • 2021-09-30
    • 2019-08-21
    • 2019-10-16
    • 2021-08-04
    • 2020-08-17
    • 2021-09-04
    • 2022-01-05
    • 2021-08-02
    • 2021-03-16
    相关资源
    最近更新 更多