You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.01 20:45:03