尝试索引字段"LocalPlayer"(nil值) [英] attempt to index field 'LocalPlayer' (a nil value)

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

问题描述

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

i have been trying to fix this problem in my game: "attempt to index field 'LocalPlayer' (a nil value)"

但是我没有做过任何努力 这是代码:

but nothing i tried to do worked here is the code:

请不要介意极其无效的代码行

please do not mind the extremely un-efficient lines of code

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)

这是我收到的错误消息:

and this is the error message i get:

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

推荐答案

LocalPlayer只能在本地脚本中使用,并且如果您要更改Leaderstats,则如果您使用localplayer方式,则需要使用远程功能,否则您可以使用脚本,然后检测是否有玩家死亡,并给他们提供leaderstat值.

LocalPlayer can only be used in localscripts, and if you are changing leaderstats, you would need to use remotefunctions if your using the localplayer way, or you could use a script and then detect is a player dies and give them a leaderstat value.

PS.如果您对roblox感兴趣,我很好建议 https://scriptinghelpers.org/,它是出色的roblox脚本问答.答:

PS. If your into roblox I very well recommand https://scriptinghelpers.org/, it is a great roblox scripting Q&A.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆