问题描述
我一直在尝试在游戏中解决此问题:尝试索引字段'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 workedhere 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值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!