im trying to achieve an name generator for roblox, heres the current code
--FUNCTIONS REQUIRED FOR GENERATING RANDOM LETTERS
local random = Random.new()
local letters = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}
function getRandomLetter()
return letters[random:NextInteger(1,#letters)]
end
function getRandomString(length, includeCapitals)
local length = length or 10
local str = ''
for i=1,length do
local randomLetter = getRandomLetter()
if includeCapitals and random:NextNumber() > .5 then
randomLetter = string.upper(randomLetter)
end
str = str .. randomLetter
end
return str
end
--actual code
game.ReplicatedStorage.Start.OnServerEvent:Connect(function(plr,numberofstring,capital)
while true do
print('ok')
print(getRandomString(numberofstring,capital))
local filter
local filteredmessage
local success,err = pcall(function()
filter = game:GetService("TextService"):FilterStringAsync(getRandomString(numberofstring,capital))
end)
if success then
--yee
else
filteredmessage = "ROBLOX" -- i cant do returns as it will break the loop so i instead change the generated name to a taken username
end
local success,err = pcall(function()
filteredmessage = filter:GetChatForUserAsync(plr.UserId)
end)
if success then
--yee (again)
else
filteredmessage = "ROBLOX" -- i cant do returns as it will break the loop so i instead change the generated name to a taken username
end
local success, username = pcall(game:GetService("Players").GetNameFromUserIdAsync, game:GetService("Players"), filteredmessage)
if not success and username then
print(filteredmessage)
end
filter = ""
filteredmessage = ""
print('end')
task.wait(0.5)
end
end)
it always prints “ROBLOX”, no idea why.