Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 8 years ago

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

Log in to vote
2
Answered by
dyler3 1510 Moderation Voter
8 years ago

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

0
Oh, it worked, cheers! :D Hyperclux 65 — 8y
0
Good to hear. Glad I could help :P dyler3 1510 — 8y
Ad

Answer this question