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

How do I change the text of a textLabel within a script?

So, I have been trying to change the text of a TextLabel, but it dosen't work at all. It's stuck at "Test1", does anyone know what to do?

textLabel = game.StarterGui.ScreenGui.TextLabel

while true do 
	
	if game.Players.NumPlayers > 1 then
		
		textLabel.Text = "Game starting.."
	
	else
		textLabel.Text = "Test1"
		wait(0.33)
		textLabel.Text = "Test2"
		wait(0.33)
		textLabel.Text = "Test3"
		wait(0.33)
	end		
	
	wait()
end

1 answer

✓ Accepted answer

Your problem is that you're trying to use the StarterGui to change it.

When a player spawns they have a descendant of them named 'PlayerGui' which is what they see on their screen. Everything gets copied from the StarterGui, and put into the PlayerGui upon spawning. Therefore, whatever you change in the StarterGui has no effect on what the player sees.


To fix this, we'll need to adjust your script to work with this concept.

One way that you can do this would be to put the script into the TextLabel, and change it to this:

textLabel = script.Parent --Simply uses the parent property to get the textlabel

while true do 
	if game.Players.NumPlayers > 1 then
		textLabel.Text = "Game starting.."
	else
		textLabel.Text = "Test1"
		wait(0.33)
		textLabel.Text = "Test2"
		wait(0.33)
		textLabel.Text = "Test3"
		wait(0.33)
	end     
	wait()
end

Now this should work!


Anyways, if you have any further problems/questions, please leave a comment below, and I'll see what I can do. Hope I helped :P

2 comments

0

Oh, it worked, cheers! :D

0

Good to hear. Glad I could help :P

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