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

How do I add more then one value to this random text code? ANSWERED

Im making this for a random gui text. What do I add?

while true do wait()
	
	local random = math.random(1,2,3,4)
	
	if random == 1 then
		script.Parent.Text = "Loading some rare pets.."
		wait()
	elseif random == 2 then
		wait()
		script.Parent.Text = "Loading home base..."
	elseif random == 3 then
		wait()
		script.Parent.Text = "Loading the pet hospital..."
	elseif random == 4
		wait()
		script.Parent.Text = "Loading pet eggs..."
	
	end
end


2 answers

✓ Accepted answer

Here ya go, you can put as many lines as you want:

local Texts = {
	"Loading some rare pets...",
	"Loading home base...",
	"Loading the pet hospital...",
	"Loading pet eggs...",
	"Loading some other stuff...",
	"Loading you...",
	"Loading the part you will spawn on...",
	"And the list goes on...",
}

local TimeToSwitch = 0.1 --Time till new text pops up

while true do
	local ChooseText = math.random(1,#Texts)
	script.Parent.Text = Texts[ChooseText]
	
	wait(TimeToSwitch)
end

EDIT Op and I talked in chat, he wanted to add an effect. This is how you can do so:

local AmountOfPeriods = 3 --This is how many periods you have in each text, in this case we have 3
local TimeToSwitch = 1 --Time till new text pops up
local Texts = {
	"Loading some rare pets...",
	"Loading home base...",
	"Loading the pet hospital...",
	"Loading pet eggs...",
	"Loading some other stuff...",
	"Loading you...",
	"Loading the part you will spawn on...",
	"And the list goes on...",
}


while true do
	local ChooseText = math.random(1,#Texts)
	local selectedText = Texts[ChooseText]
	local Num = #selectedText - AmountOfPeriods + 1
	
	for i = 1, AmountOfPeriods do
		script.Parent.Text = string.sub(selectedText, 1, Num)
		Num = Num + 1
		wait(0.5)
	end
	
	wait(TimeToSwitch)
end

1 comment

0

this is way better than my answer good job man

You need to remove all those numbers in the math.random() variable.

The math.random() function picks a random number between argument 1 and 2.

Change this:

local random = math.random(1, 2, 3, 4)

Into this:

local random = math.random(1, 4) --picks a random number between 1 and 4

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