Roblox 为什么我在游戏中无法获取 Players.LocalPlayer.Character

Cra*_*ney 3 lua roblox luau

我一直在关注许多使用以下内容的教程:

game.Players.LocalPlayer.Character
Run Code Online (Sandbox Code Playgroud)

然而,每次我尝试运行它时,我都会收到一条错误消息:

Players.icrann.PlayerScripts.Script:2:尝试索引字段“Character”(零值)

我正在尝试使用此代码来查找 HumanoidRootPart,以便我可以检查玩家的位置。game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")

并且还使播放器能够运行,即使我尝试使用工具箱中的脚本,它仍然无法工作。game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = 25

在每种情况下都会产生相同的错误。我还在资源管理器中添加了 Players 文件夹的屏幕截图。

探险家

预先感谢您的帮助。

Kyl*_*aaa 5

我相信你有一个时间问题。PlayerScripts 在玩家加入时执行,并且在脚本执行时您的角色可能尚未加载。

将 LocalScript 移至 CharacterScripts 中,这将导致脚本在角色加载后触发。