How to loop texts?

Hi, I’ve come to ask for help on how to make a loop, and I really don’t know how to merge it with a math.random, and that’s why I’m asking for help.
What I want to do is change the texts every few seconds, and my script only changes once and I don’t know how to make it change with the loop.

local randomtext = math.random(1, 6)
local ContadorDeTextos = 0

repeat
while true do
	wait(0.1)
	if randomtext == 1 then
		script.Parent.Texto.Informacion1.Text = "al jugar deberás seguir las reglas las cuales son. Respetar, No molestar (solo podrás hacerlo si bien eres amigo suyo o usando un role), Ser mayor de  14 años. Recuerda que jugar entre amigos es mas divertido, y que también fortalece la amistad. !Recuerda conseguir trabajos, comprar,  Rolear y todo lo que se te venga a la mente!"
		script.Parent.Texto.Informacion2.Text = "Cuando vayas a buscar trabajo recuerda que hay muchos trabajos y cada uno es bueno a su manera, y mientras mas trabajes mas dinero obtendrás, y si te quieres ir hacía al lado oscuro, busca el trabajo de vendedor de caramelos, es el que te dará mas dinero y el mas complicado. Cuando obtengas dinero te lo podrás gastar en armas, ropa, accesorios, vehículos, construir casas, comprar decoraciones de hogar, construir fabricas, etc. etc."
		script.Parent.ImageLabel.Image = "asdasda"
	elseif randomtext == 2 then
		script.Parent.Texto.Informacion1.Text = "Este juego es uno gratuito, y claro, también tendrá gamepases, objetos Premium, aunque no es obligatorio que los compren pues es un juego para entretenerse, también podrán apoyarme a seguir mejorando y para contratar gente, esto ayudara a este juego y se volverá uno completamente diferente al de los demás"
		script.Parent.Texto.Informacion2.Text = "Mi objetivo es hacer un juego que se pueda jugar con historia, también que lo puedan jugar en modo, el servirá para rolear, divertirse con amigos, trabajar, comprar y hacer misiones. El modo historia tendrá una campaña diferente al de los demás juegos, tendrá cinemáticas, historia, modo de guardado, misiones, esto solo será para que quieras jugar algo nuevo y estará próximamente"
		script.Parent.ImageLabel.Image = "asdasda"
	elseif randomtext == 3 then
		script.Parent.Texto.Informacion1.Text = "asdasdasdasdfdsf"
		script.Parent.Texto.Informacion2.Text = "asdasdasda"
		script.Parent.ImageLabel.Image = "asdasda"
	elseif randomtext == 4 then
		script.Parent.Texto.Informacion1.Text = "dfgdfgd"
		script.Parent.Texto.Informacion2.Text = "asdasdasda"
		script.Parent.ImageLabel.Image = "asdasda"
	elseif randomtext == 5 then
		script.Parent.Texto.Informacion1.Text = "sfddfsgfthj"
		script.Parent.Texto.Informacion2.Text = "asdasdasda"
		script.Parent.ImageLabel.Image = "asdasda"
	elseif randomtext == 6 then
		script.Parent.Texto.Informacion1.Text = "jghjghjghjgjh"
		script.Parent.Texto.Informacion2.Text = "asdasdasda"
			script.Parent.ImageLabel.Image = "asdasda"
		end
	end
until ContadorDeTextos == 10

Move this line Inside of the While true do loop, this will generate a new random number every time the loop restarts, which should in turn also give you a random text.

3 Likes

Also one more thing I want to mention, the repeat loop will never reach until, once the while true do loop starts, it’ll never stop looping unless you break it.

Looking at the code I can tell you want to run the loop a set amount of times, this is where a for loop comes in handy.

A for loop is written like this:

for index = startNumber, endNumber, iteration do
    --do stuff
end

index = the current loop iteration the for loop is running
startNumber = Where you want index to start
endNumber = Where index will end
iteration = index will go up by the iteration amount (this is optional and doesn’t need to be included in a for loop)

The for loop you would be looking for looks something like this:

for i = 1, 10 do
    --do stuff
end

this will run the for loop 10 times and stop.

2 Likes