【问题标题】:attempt to index upvalue 'player' (a nil value)尝试索引 upvalue 'player'(一个 nil 值)
【发布时间】:2019-10-10 16:42:37
【问题描述】:

请帮助我!我正在制作游戏,但我一直遇到同样的问题

我尝试了很多东西,但没有任何效果


script.Parent.Humanoid.Died:Connect(function()
    print("yeet")
    player.leaderstats.PuzzlePieces.Value =  player.leaderstats.PuzzlePieces.Value + 1
end)

【问题讨论】:

  • Playerplayer?你为什么使用player 作为升值?不应该是全局变量吗?
  • 你能把脚本改正吗?我不明白你的意思

标签: lua roblox


【解决方案1】:

错误:attempt to index upvalue 'player' (a nil value) 表示您正在尝试使用尚未定义的变量。在这种情况下,“玩家”。所以你只需要通过将它指向game.Players中的正确对象来创建播放器变量

我假设你在玩家模型中拥有这个脚本

玩家模型和类人机器人存在于game.Workspace 中,leaderstats 对象存在于game.Players 中的一个对象中。你需要两个人互相交谈。

local playerModel = script.Parent
playerModel.Humanoid.Died:Connect(function()

    -- use the player's name to find the player object in game.Players
    local playerName = playerModel.Name
    local player = game.Players[playerName]

    -- update the leaderboard
    player.leaderstats.PuzzlePieces.Value =  player.leaderstats.PuzzlePieces.Value + 1
end)

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-16
    • 2017-08-10
    • 2017-04-22
    • 1970-01-01
    • 2016-05-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多