首页 > 解决方案 > 罗布洛克斯 || game.Players.LocalPlayer.Name 尝试调用字符串值?

问题描述

local Player = Players.LocalPlayer or Players:GetPropertyChangedSignal("LocalPlayer"):Wait()

if not Settings.CustomAppDesc then
    AppDescLabel.Text("Welcome, "..Player.Name) -- Error: attempt to call a string value
end

不知道为什么会这样。

谢谢,尼克劳斯

标签: luaroblox

解决方案


attempts to call a string value

不知道为什么会这样

好吧,为什么会发生这种情况实际上很明显。

AppDescLabel.Text("Welcome, "..Player.Name)

AppDescLabel.Text 就是,顾名思义,文本和文本存储在字符串值中。

将调用运算符放在()字符串值之后是尝试调用对 Lua 没有任何意义的字符串值,因此不允许和拒绝并显示错误消息。

如果要设置 AppDescLable 的 Text 属性,则需要为其分配一个字符串值。

AppDescLabel.Text = "Welcome, " .. Player.Name

请参考https://developer.roblox.com/en-us/api-reference/property/TextLabel/Text


推荐阅读