【发布时间】:2020-06-20 05:12:00
【问题描述】:
我正在尝试创建一个每 5 秒更改一次的 TextLabel。我有这个代码,但它不起作用。
local player = game.Players:GetPlayerFromCharacter(part.Parent) —this is our gateway to getting the PlayerGui object.
local PlayerUI = player:WaitForChild(“PlayerGui”)
local txtLabel = PlayerUI[“Welcome_Text”].TextLabel
while x < 1 do
wait(5)
txtLabel.Text = “Welcome to The Shadow Realm!”
wait(5)
txtLabel.Text = “Warning: This game contains scenes that may be too scary for some roblox players”
end
我收到一条错误消息。
ServerScriptService.Script:2:尝试索引全局“部分”(零值)
我不知道把我的 gui 放在哪里。
【问题讨论】:
-
你没有在代码中的任何地方声明变量
'part',也就是说,它是nil——因此出现attempt to index global 'part' (a nil value)的错误。您还将遇到与变量'x'相同的问题,因为它未声明。另外,您的上述代码将放在哪里,它会在Script或LocalScript中吗? -
抱歉,我不小心剪掉了
x=0位。代码将放置在脚本中,而不是本地脚本中。