尝试索引 'LocalPlayer' 字段(一个空值)

我一直在尝试解决我的游戏中的这个问题: "尝试索引 '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)

这是我收到的错误消息:

尝试索引字段 'LocalPlayer'(一个空值)
点赞
用户11285364
用户11285364

LocalPlayer 只能在本地脚本中使用,如果您要更改 leaderstats,则使用 LocalPlayer 方法需要使用 RemoteFunction,或者您可以使用一个脚本,然后检测玩家是否死亡并给他们 leaderstat 值。

PS. 如果您对 Roblox 感兴趣,我非常推荐 https://scriptinghelpers.org/,这是一个很好的 Roblox 脚本问答网站。

2019-05-24 17:45:30