0
votes

I am trying to create a TextLabel that changes every 5 seconds. I have this code, but it doesn't work.

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 

I am getting an error message that says.

ServerScriptService.Script:2: attempt to index global 'part' (a nil value)

I don't know where to put my gui.

1
You have not declared the variable 'part' anywhere in your code, that is, it is nil–hence the error that says attempt to index global 'part' (a nil value). You will also run into the same issue with the variable 'x' because it is undeclared. Also, where will your above code be placed, and will it be in a Script or LocalScript? - Personage
Sorry, I accidentally cut out the x=0 bit. The code will be placed in a script, not a local script. - Rpergy

1 Answers

0
votes

If I am correctly understanding what you are trying to do, you should be able to create a ScreenGui and place it in StartGui so that every player will have it copied to his PlayerGui when he joins the game. You could place a LocalScript inside of that GUI that would control the text on screen.

I see your LocalScript looking something like this:

-- 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)

Making this a LocalScript within a client-side GUI shifts the overhead to the client and eliminates the need to use the method Players::GetPlayerFromCharacter.