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

TextLabel not showing strings from a table?

Asked by 9 years ago

I'm trying to get my GUI to show text from the table I've made instead of copying and pasting the text change over and over. The output said this: 17:05:57.359 - Players.Player1.PlayerGui.MainBarManagement:18: bad argument #3 to 'Text' (string expected, got table)

01local Texts = {
02    "TESTING",
03    "MEMES"
04}
05 
06 
07MainBarText.Text = Texts
08wait(2)
09for i = 0,1,0.1 do -- Turn invisible
10MainBarText.TextTransparency = i
11wait()
12end
13 
14MainBarText.Text = Texts
15for i = 1,0,-0.1 do
16    MainBarText.TextTransparency = i
17    wait()
18end

1 answer

Log in to vote
2
Answered by 9 years ago

It's exactly what the error message says. The Text property expected a string value, but you gave it a table value. If you want to make a text read strings from a table, you're going to have to iterate the table with a for loop, and assign each one of those individual texts to that textlabel. Like this:

01local Texts = {
02    "TESTING",
03    "MEMES"
04}
05 
06for i,v in ipairs(Texts)do
07    MainBarText.Text = v
08    wait(1) -- probably going to need this so we can actually see the texts changing
09end
10 
11for i = 0,1,0.1 do -- Turn invisible
12    MainBarText.TextTransparency = i
13    wait()
14end
15 
View all 26 lines...

Now, we could actually make this a bit cleaner by making a function that changes the text for us, using the same for loop. Like this:

01local Texts = {
02    "TESTING",
03    "MEMES"
04}
05 
06local function IterateTexts(Table, Time)
07    for i,v in ipairs(Table)do
08        MainBarText.Text = v
09        wait(Time)
10    end
11end
12 
13IterateTexts(Texts, 1) -- Going through the "Texts" table, changing the text every 1 second.
14 
15for i = 0,1,0.1 do -- Turn invisible
View all 25 lines...

Hope this helped.

Ad

Answer this question