Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I make a math.random generator BUT with words?

Asked by 4 years ago
Edited 4 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.

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

Log in to vote
1
Answered by
Roger111 347 Moderation Voter
4 years ago
Edited 4 years ago

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())
0
You mean math.random(1,#wordlist) . You forgot the start number. PrismaticFruits 842 — 4y
0
Nope! You don't need to put the start number. Roger111 347 — 4y
1
When you call math.random() with one parameter, it will immediately get a number within that range. Nickuhhhhhhhhhhhhhhh 834 — 4y
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 VerdommeMan 1479 — 4y
Ad

Answer this question