Lua 尝试索引字段';本地播放器';(零值)

Lua 尝试索引字段';本地播放器';(零值),lua,roblox,Lua,Roblox,我一直在尝试在游戏中解决此问题: “尝试索引字段'LocalPlayer'(一个空值)” 但我试着做的都没用 代码如下: 请不要介意极不高效的代码行 local player = game.Players.LocalPlayer script.Parent.Humanoid.Died:Connect(function() print("yeet") script.Parent.Parent.Parent.Players.LocalPlayer.leaderstats.Puzzl

我一直在尝试在游戏中解决此问题: “尝试索引字段'LocalPlayer'(一个空值)”

但我试着做的都没用 代码如下:

请不要介意极不高效的代码行

local player = game.Players.LocalPlayer

script.Parent.Humanoid.Died:Connect(function()
    print("yeet")
    script.Parent.Parent.Parent.Players.LocalPlayer.leaderstats.PuzzlePieces.Value = script.Parent.Parent.Parent.Players.LocalPlayer.leaderstats.PuzzlePieces.Value + 1
end)
这是我收到的错误信息:

attempt to index field 'LocalPlayer' (a nil value)

LocalPlayer只能在localscripts中使用,如果您正在更改leaderstats,则如果您使用LocalPlayer方式,则需要使用remotefunctions,或者您可以使用脚本,然后检测是否有播放机死亡并为其提供leaderstat值

注:如果我非常推荐你加入roblox,这是一个很棒的roblox脚本问答。

可能与