attempt to index upvalue 'player' (a nil value)

别说谁变了你拦得住时间么 提交于 2019-12-25 18:27:58

问题


please help me! I am making a game but i keep running into the same problem

i tried many things but nothing worked


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

回答1:


The error : attempt to index upvalue 'player' (a nil value) means that you are trying to use a variable that has not been defined. In this case "player". So you just need to create the player variable by pointing it at the right object in game.Players

I'm assuming that you've got this Script inside a player's model

The player model and humanoid live in game.Workspace the leaderstats object lives in an object in game.Players. You need the two to talk to each other.

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)

Hope this helps



来源:https://stackoverflow.com/questions/56286539/attempt-to-index-upvalue-player-a-nil-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!