为什么此更改GUI代码对Roblox Studio不起作用?

时间:2020-03-07 19:32:24

标签: lua roblox

我正在尝试创建一个每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:尝试索引全局'part'(nil值)

我不知道将GUI放在哪里。

1 个答案:

答案 0 :(得分:0)

如果我正确理解了您要做什么,那么您应该可以创建一个ScreenGui并将其放置在StartGui中,以便每个玩家都可以将其复制到他的{{1} },当他加入游戏时。您可以在该GUI内放置一个PlayerGui,以控制屏幕上的文本。

我看到您的LocalScript看起来像这样:

LocalScript

在客户端GUI上设置-- Customize names on your own; these are just generic placeholders. -- The structure of the GUI would look like this: -- -- ScreenGui -- LocalScript -- Frame -- TextLabel local WELCOME = "Welcome to the Shadow Realm!" local WARNING = "Warning! This game contains scenes that may be too scary for some players" local runService = game:GetService("RunService") local gui = script.Parent local frame = gui.Frame local label = frame.TextLabel local function update_text() label.Text = WELCOME wait(5) label.Text = WARNING return end runService.RenderStepped:Connect(update_text) 可以将开销转移到客户端,并且无需使用方法LocalScript