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 make a math.random generator BUT with words?

For example, instead of having lets say 1,5 it would be: hello,(or) goodbye

Okay so im trying to make this script print out words just like math.random prints out numbers, I know how to do math rand b ut not with words

Here is my math.random

while true do
	
	
	wait(0.8)
	
local variable1 =  math.random(1,4)
local variable2 = math.random(5,10)
	
	
	print(variable1, variable2)


end

Any help appreciated

1 answer

✓ Accepted answer

ANSWER: You will still need a random number, and you will use that random number to get a random index from an Array of words.

Example:

local wordList = {
	"Hello",
	"Goodbye",
	"Yes",
	"No",
	"What is going on here?"
}

function randomWord()
	return wordList[math.random(#wordList)]
end

print(randomWord())
print(randomWord())
print(randomWord())

4 comments

0

You mean math.random(1,#wordlist) . You forgot the start number.

0

Nope! You don't need to put the start number.

1

When you call math.random() with one parameter, it will immediately get a number within that range.

0

??? if you call math.random() with 1 arg, then it will return a number in the range of [1,arg] see https://developer.roblox.com/en-us/api-reference/lua-docs/math

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