Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would one change a text gui within a script?

Hi, I have recently started creating a racing game in Roblox. In said racing game, there is a short intermission before the race starts. I want to make it so that the text in a GUI changes every five seconds to tell the players when the race is starting. I have already started typing a script, but it doesn't work? Here it is:

game.StarterGui.ScreenGui.TextLabel.Text = "The race is starting soon."
wait(5)
game.StarterGui.ScreenGui.TextLabel.Text = "Get to your cars!"
wait(5)
game.StarterGui.ScreenGui.TextLabel.Text = "The race is starting!"

I don't really understand why it doesn't work.

2 answers

✓ Accepted answer

You're changing the GUI in StarterGui. You need to change the GUI in PlayerGui. StarterGui is used to parent GUIs to PlayerGui. Put this in a LocalScript in the TextLabel.

For loop

Tables

-- table indexes start at 1 in Lua
local Messages = {
	-- index of 1
	"The race is starting soon.";
	-- index of 2 
	"Get to your cars!";
	-- index of 3
	"The race is starting!"
}

-- for loop
for i = 1, #Messages do 
	-- Messages[index]
	script.Parent.Text = Messages[i]
	wait(5) 
end

1 comment

0

I actually tried to put the script in serverscriptservice, because right after the stop light needs to change colors.

When the player joins the game, the things in the starterGUI are cloned into the playerGUI. So, instead of accessing the GUI by something such as game.StarterGui, one of the best ways to access it is doing something such as:

script.parent.TextLabel.Text = "The race is starting soon."
wait(5)
script.parent.TextLabel.Text = "Get to your cars!"
wait(5)
script.parent.TextLabel.Text = "The race is starting!"
-- Obviously, if the textLabel can't be found through script.parent you will have to change it depending on where you have stored the script.

If this is the correct answer, please help me out just as I have helped you and accept my answer, thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.