Randomized Text not showing up in TextLabel

To be clear, the random text is working perfectly and printing into output.I will not show my variable parts unless someone feels it’s needed. I have been trying to load the random text generated and put it into the TextLabel (Sentence). I am not getting any script errors but it isn’t working. I have tried this listed below and not too different variations of it:

local quote = game.StarterGui.QuoteGen.Sentence.Text
quote = variable1, variable2, variable3

I realize I’m writing it more like Python than Lua, but this is the best I can do after reading a number of articles on Developer Hub like Text and Strings. Any help is very much appreciated. Thanks, and sorry in advance if this is just me being dumb.

Try the following

local quote = game.StarterGui.QuoteGen.Sentence
quote.Text = variable1..variable2..variable3

Two dots can be used to concatenate strings in lua.

(Fixed object mistake brought to my attention by post #4)

Is the text loading in? :thinking:

There are 2 problems with your code:

  1. Like @Naco88 has already said, you use 2 dots to concatenate strings. The method you are using will just put the variable1 inside quote and that’s it. The variable2 and variable3 are not being put inside the quote string.

  2. When you set the reference to an object inside a variable, the reference gets stored in the variable but when you set the reference to a property, the value in the property will get stored in the variable, not the actual reference itself. You are setting the quote variable to the value in the text property of the textlabel, not to the actual text property itself.

Replace that code with this code and let me know if it helped:

local quote = game.StarterGui.QuoteGen.Sentence
quote.Text = variable1..variable2..variable3
1 Like

This did not work sadly. I used an usual way to generate random words based off numbers from a math.Random earlier in the script. Here’s an example of one of the if statements:
if selectedIndex1 == 1
then variable1 = ("Text")

I have put it into a ButtonClick function that these if statements lay so I can get different variables every time, and the last thing is these lines to put the variables into the Text. I also attempted to put quote.Text = variable1 into one of the if statements, but I got the Error “attempt to index string with ‘Text’” . Hopefully this information helps.

Edit: Here is a video of the situation. It is showing up in Output, but not in the actual Text even though the lines are in the script

local quote = game.StarterGui.Quote.Sentence

I suspect this is the problem.
Here you’re editing what’s in the StarterGui, but not what’s already under your own GUI. The StarterGui simply replicates its contents to the PlayerGui folder of new players, but does not replicate changes made to it to current players too. Try accessing the GUI that is already in your PlayerGui instance first. Considering that you’re using a LocalScript, you can access this via LocalPlayer.

local quote = game.Players.LocalPlayer.PlayerGui.Quote.Sentence
1 Like