Random text on a gui not working

local Lbl = script.Parent.a
local text = {
	"Have Fun!";
	"Contains 2% Sugar";
	"Contains 50% Code";
	"Remember To Go To School";
	"2 Cool 4 School";
	"Made With Love";
	"Made By Denys";
	":p";
	"Remember To Like The Game";
	"The game is best played with volume on";
}
while true do
	Lbl.Text = math.random(text)
	wait(2)
end

return text
while true do
	Lbl.Text = text[math.random(1,#text)]
	wait(2)
end

return text

That should work, you need to add the # and text table with square brackets before

Lbl.Text = text[math.random(1, #text)]

This will work

math.random() is used for getting a random number, and for your case, you want a random position (integer) from the table. You could do:

Lbl.Text = text[math.random(1, #text)]
--text[integer]
--math.random(starting at 1, #amount of sentences)
1 Like

This doesn’t work. You’re setting Lbl.Text to be equal to a number between 1 and 10, since “text” has 10 elements.

What? I know what I’m doing, That’s why I’m putting the table before it…

Okay then. I think I saw something different and also the fact that it’s edited is kind of sus

it does not work and i dont know why

Replace the table with this:

local text = {"Have Fun!", "Contains 2% Sugar", "Contains 50% Code", "Remember To Go To School", "2 Cool 4 School",  "Made With Love", "Made By Denys", "Remember To Like The Game", "The game is best played with volume on"}

The second option is to keep the current table but replace the ; with , instead. You won’t need one at the very last text either.

local text = {
	"Have Fun!",
	"Contains 2% Sugar",
	"Contains 50% Code",
	"Remember To Go To School",
	"2 Cool 4 School",
	"Made With Love",
	"Made By Denys",
	":p",
	"Remember To Like The Game",
	"The game is best played with volume on"
}

Next off, your math.random is wrong. It should be:

while true do
	Lbl.Text = text[math.random(1,#text)]
	wait(2)
end

Hope this helps! :smiley:

1 Like

it does not work i tried both tables but it does not work maybe i need a script insted of a module script