Roblox LocalScript第93行attempt to index with 'Name'错误求助
问题原因
你触发该报错的核心原因是没有在代码中提前定义并获取plr(玩家对象)变量,Lua解析器找不到plr对应的实例,自然无法索引它的Name属性。
解决方法
因为你的代码是运行在PlayerGui内的LocalScript,直接用Roblox提供的LocalPlayer属性获取本地玩家对象即可,修正后的代码如下:
-- 新增plr变量定义,获取本地玩家实例 local plr = game.Players.LocalPlayer local Frame = script.Parent.Frame local Text = script.Parent.Frame.TextLabel Text.Text = "Lets Start" .. plr.Name .." "
注意事项
game.Players.LocalPlayer仅可在客户端运行的LocalScript中调用,无法在服务器端Script中使用- 若需要在服务器脚本中获取对应玩家实例,需通过远程事件、远程函数的回调参数传递获取,不可直接调用
LocalPlayer
内容的提问来源于stack exchange,提问作者ISGamer
相关产品推荐
相关产品推荐

