Search code examples
luaroblox

Roblox studio - How do I change a TextLabel text by script


I want to change a TextLabel's text.

I have this simple script:

local text = script.Parent.Text

wait(2)

text = "Hey, there!"

But when I play it, the Text just stays to the default label. - no error or warning


Solution

  • When you save the Text property into a variable, you are simply holding a snapshot of the text string at that moment in time. Updating the variable does not also update the TextLabel. You must explicitly set the Text property to update it.

    So, in a LocalScript, try this :

    local textLabel = script.Parent
    
    wait(2)
    
    textLabel.Text = "Hey, there!"