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 this generate 4 characters instead of 1?

Namee = script.Parent.Namee

Nameo = script.Parent.Nameo

--Characters Here:

local characters = {"_", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "a", "s", "d", "f", "g", "h", "j", "k", "l", "z", "x", "c", "v", "b", "n", "m", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "A", "S", "D", "F", "G", "H", "J", "K", "L", "Z", "X", "C", "V", "B", "N", "M", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}

--Length Here:

local charLength = 4

local cache = {}

--/CONFIGURATION--

  

--You Will See Random Generated Word In Output Window

--To Start It Disable This Script And Enable

  

while true do wait(5)

local word = ""

for i = 1, charLength do

local randNum = math.random(1, #characters)

word = word .. characters[randNum]

print(word)

Nameo.Text = word

wait()

word = ""

end

local Players = game:GetService("Players")

local cache = {}

function GetUserIdFromUsername(name)

-- First, check if the cache contains the name

if cache[name] then return cache[name] end

-- Second, check if the user is already connected to the server

local player = Players:FindFirstChild(name)

if player then

cache[name] = player.UserId

return player.UserId

end

-- If all else fails, send a request

local id

pcall(function ()

id = Players:GetUserIdFromNameAsync(name)

end)

cache[name] = id

return id

end

if (GetUserIdFromUsername(Namee.Text)) == nil then

Namee.Text = ("Not Taken")

script.Parent.Image = "rbxassetid://891981050"

else

Namee.Text = (GetUserIdFromUsername(Nameo.Text))

script.Parent.ImageTransparency = 0.6

script.Parent.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=200&y=200&Format=Png&userid="..(GetUserIdFromUsername(Nameo.Text))

end

end

The output generates things such as v, z, 1, d, _, 9, m, among other things it's supposed to generate 4 characters at once, not just one. this is within a gui, it's supposed to automatically generate usernames that aren't taken when it finds them.

2 comments

0

My "manual" version of this broke somehow too, it used to work...

0

The comment I said above I found was an easy fix so the "manual" version was fixed

1 answer

✓ Accepted answer

I couldn't really red your code because it wasn't indented, but if you want it to assemble a string composed of those four characters, just use a for-loop and add a random character to the word. I'll post a little demonstration below.

characters = {"a", "b", "c", "d"}

function GetRandomWord(length)
	local word = ""
    for i = 0, length, 1 do
		word = word .. characters[math.random(1, #characters)]
	end
	return word
end
print(GetRandomWord(100))

4 comments

0

I want the potential for every character listed in characters but it chooses only 4 at random.

0

That's because there is only four in the characters array I made. Just add more and it will choose from more. You already made your own array of characters, just reuse that.

0

That didn't work for my usage, I want to put it into a textlabel

0

Well, then simply store the result by doing "local word = GetRandomWord(4)", and then set the text of the TextLabel by doing "textLabel.Text = word"

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