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)
01 | local Texts = { |
02 | "TESTING" , |
03 | "MEMES" |
04 | } |
05 |
06 |
07 | MainBarText.Text = Texts |
08 | wait( 2 ) |
09 | for i = 0 , 1 , 0.1 do -- Turn invisible |
10 | MainBarText.TextTransparency = i |
11 | wait() |
12 | end |
13 |
14 | MainBarText.Text = Texts |
15 | for i = 1 , 0 ,- 0.1 do |
16 | MainBarText.TextTransparency = i |
17 | wait() |
18 | end |
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:
01 | local Texts = { |
02 | "TESTING" , |
03 | "MEMES" |
04 | } |
05 |
06 | for 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 |
09 | end |
10 |
11 | for i = 0 , 1 , 0.1 do -- Turn invisible |
12 | MainBarText.TextTransparency = i |
13 | wait() |
14 | end |
15 |
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:
01 | local Texts = { |
02 | "TESTING" , |
03 | "MEMES" |
04 | } |
05 |
06 | local function IterateTexts(Table, Time) |
07 | for i,v in ipairs (Table) do |
08 | MainBarText.Text = v |
09 | wait(Time) |
10 | end |
11 | end |
12 |
13 | IterateTexts(Texts, 1 ) -- Going through the "Texts" table, changing the text every 1 second. |
14 |
15 | for i = 0 , 1 , 0.1 do -- Turn invisible |
Hope this helped.