本文介绍了尝试索引升值的“玩家"(零值)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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)

推荐答案

错误:试图索引升值的'player'(nil值) 表示您正在尝试使用具有以下特征的变量:尚未定义.在这种情况下为玩家".因此,您只需要通过将播放器变量指向game.Players

我假设您已经将该脚本包含在玩家的模型中

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

玩家模型和类人动物生活在game.Workspace中,leaderstats对象生活在game.Players中的对象中.您需要两者互相交谈.

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)

希望这会有所帮助

这篇关于尝试索引升值的“玩家"(零值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 18:39