How would I make a GUI that puts words together?

I’m not sure if its in the right category. Please tell me where to put this if I’m wrong.

I am trying to make something like the Random Name Generator game but instead of usernames, it just randomizes the words I put in the script and then comes with a random game name. I’m trying to make this so it could help me with game ideas in the future. It might also help other devs.\

I’m not much of a scripter so please teach me how to do this. Note: You don’t need to directly give it to me, just guide me to where to go. Thanks!

local RandomWords = {
	["1"] = "Name1";
	["2"] = "Noob";
	["3"] = "bruh";

local RandomNumber = math.random(1,#RandomWords)
local ChosenWord  = RandomWords[tostring(RandomNumber)]
-- Do something with "ChosenWord"
-- I didn't test this

not really what they asked for

Use this function, it should word for what you need :slight_smile:

local words = {} -- Make sure to put all the possible words in here :)

local getRandomName = function(wordCount) -- Here is the function to use :D
   local name = ""
   for x = 1, wordCount do
      name = name .. words[math.random(1, #words)] .. " " -- You don't have to include the space, delete it if you don't want a space between words :)
   return name

-- Example
local newName = getRandomName(4) -- Put the number of words you want to replace that number
1 Like

I wasn’t sure what he meant with a “Random game name”. so I made a randomizer that chooses a random word.

Would I put this in a GUI? Where would I put that?

yea I think you were on the right track, I was just saying since the title said to put them together not just a random word

Ohhh you want the gui to do it also? Just use the same idea and do this :slight_smile:. Put this script inside of a Text Label

local guiText = script.Parent

local words = {"Word1", "Word2", "Word3"} -- Make sure to add words in here! YOu can add as many as you like

local setRandomName = function(wordCount)
   local name = ""
   for x = 1, wordCount do
      name = name .. words[math.random(1, #words)] .. " " -- You do not have to have this space, delete if you don't want a space between words
   guiText.Text = name
   return name

-- Example
setRandomName(5) -- Change this for the length of the name in words

no need to return name now that you are doing gui changes

I know, just in case they want to keep track of it though :slight_smile:

I know i’m late to the party but just wanted to mention this, you can shorten this line to

name ..= words[math.random(#words)] .. " " 

..= is a shorthand for var = var .., and specifying 1 argument will treat the minimum as 1 and the maximum as the number you gave it, basically the same as how you have done it

Also, since you never use the variable in the for loop, you can change it to _ to show that it is a dummy/unused variable.

1 Like