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

人走茶凉 提交于 2019-12-25 18:36:47

问题


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)

回答1:


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. If your into roblox I very well recommand https://scriptinghelpers.org/, it is a great roblox scripting Q&A.



来源:https://stackoverflow.com/questions/56289849/attempt-to-index-field-localplayer-a-nil-value

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