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

I need help indexing through a list with ipairs, and making that value the text on my textlabel?

I'm trying to make a loading screen which shows tips and random messages kind of like the Minecraft loading screen, I have this local script as a child under my text label, and am trying to change the text by using ipairs to cycle through the array, can anyone help me? also if there's a mistake please don't harass me I'm from python and c#

Code:

local wordArray = {"LOADING","Sushi tastes better hot!", "SunnySavege is kind of a savage not gonna lie", "YOU ACTUALLY READ THESE MESSAGES IDIOT thank u tho -ayuu1234", "To use an object press E multiple times"}
local Txt = script.Parent.Text

for value in ipairs(wordArray) do
	Txt = value
	wait(5)
end

Thanks for your time :)

1 answer

✓ Accepted answer

You have some problems in the script, so first, on line 2 you are setting Txt variable to current text of the label which is a string. You need to set the variable to the label like

local Txt = script.Parent

and then set it's text by accessing it's property Text by doing

Txt.Text = 'Hello this is cool text'

Now your ipairs loop is also just a bit wrong, ipairs and pairs return 2 values which are Index or wizard calls it Iteration and the second value is the Value itself so your value variable is position of the element in the table. So you would have to do

local Txt = script.Parent
for Index, value in ipairs(wordArray) do
	Txt.Text = value
	wait(5)
end

And that's it.

1 comment

0

Thank you so much!

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