Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

TextLabel not showing strings from a table?

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)

local Texts = {
	"TESTING",
	"MEMES"
}


MainBarText.Text = Texts
wait(2)
for i = 0,1,0.1 do -- Turn invisible
MainBarText.TextTransparency = i
wait()
end

MainBarText.Text = Texts
for i = 1,0,-0.1 do
	MainBarText.TextTransparency = i
	wait()
end

1 answer

✓ Accepted answer

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:

local Texts = {
    "TESTING",
    "MEMES"
}

for i,v in ipairs(Texts)do
	MainBarText.Text = v
	wait(1) -- probably going to need this so we can actually see the texts changing
end

for i = 0,1,0.1 do -- Turn invisible
	MainBarText.TextTransparency = i
	wait()
end

-- again

for i,v in ipairs(Texts)do
	MainBarText.Text = v
	wait(1) 
end

for i = 1,0,-0.1 do
	MainBarText.TextTransparency = i
	wait()
end

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:

local Texts = {
    "TESTING",
    "MEMES"
}

local function IterateTexts(Table, Time)
	for i,v in ipairs(Table)do
		MainBarText.Text = v
		wait(Time)
	end
end

IterateTexts(Texts, 1) -- Going through the "Texts" table, changing the text every 1 second.

for i = 0,1,0.1 do -- Turn invisible
	MainBarText.TextTransparency = i
	wait()
end

IterateTexts(Texts, 1)

for i = 1,0,-0.1 do
	MainBarText.TextTransparency = i
	wait()
end

Hope this helped.

This discussion is preserved as it was. New answers, comments, and votes are closed.