How can I improve my auto generate text

Hello Developers! I am WEcompany! I am currently wanting to change this text from in order, to auto generated from the table. Here is what I have so far:

hints = {	
	"If you want to know more on how to play Bloxy Kart, press the book button on the left sidebar. ",
	"Tip: To win gold tier in time trials, race as fast as you can without stopping. ",
	"Time trials is a fun way to practice maps and to get more points. ",
}

while true do
	for i = 1, #hints do
		script.Parent.Value = hints[i]
		wait(5)
	end 
end

(Yes this is all on the server)

You can use math.random to randomly select an object.

hints = {	
	"If you want to know more on how to play Bloxy Kart, press the book button on the left sidebar. ",
	"Tip: To win gold tier in time trials, race as fast as you can without stopping. ",
	"Time trials is a fun way to practice maps and to get more points. ",
}

while true do
	script.Parent.Value = hints[math.random(1, #hints)] -- #hints is used to find out how many objects are in the table
	wait(5)
end

It could pick the same text 2 times in a row, so if you wanted to fix that you would have to add a check to see if the value is the same as the hint picked.

2 Likes

Hi, I’m aware that this is answered, but the code you supplied has some issues which I will discuss below:

First of all, don’t use math.random anymore as it’s considered as Depreciated by Roblox. It has been replaced by Random.new.

Second of all, there isnt really a reason to replace the original for i = 1 part, as it would work fine either way.