Username Generator Problem

Hello Developers,

I am having a problem with my username generator script. How the script works is it comes up with different combinations of characters and then checks to make sure the username is not in use on the platform using game.Players:GetUserIdFromNameAsync() wrapped in a pcall. However, for some reason, the function will tell me that the userid for the username generated does not exist when it really does.

In other words, the get userid async function is telling me that the generated usernames are not in use when they really are.

Is it because I am calling the function to fast maybe? 1 time per 5 seconds,

Thanks,

Everytime you call the function, print out what is returned. Is there an error, or is the string empty?

This is how the availability check section of the script works:

local zib
		local s, e = pcall(function()
			zib = game.Players:GetUserIdFromNameAsync(get)
		end)
	
	
	
		if zib == nil then
			print(get .. " : Not Taken")
		end

In this portion, get is the made up username and zib is the returned value of the function.

As you can see, if zib is equal to nil, then the username isn’t taken.

try:

if zib == nil or zib == "" then
	print(get .. " : Not Taken")
end

I tried this and it seems that it cut down a little bit however it is still sometimes telling me that the usernames are available when they aren’t.

-- We can discard the result as we don't use it.
local ok = pcall(game.Players.GetUserIdFromNameAsync, game.Players, name)

if not ok then
    print(name .. " is not taken!")
end

If this still isn’t reliable then I’m not sure how to fix that and it seems as though it may be a bug or limitation with Roblox itself.

On a side note, you don’t need to wrap the call to GetUserIdFromNameAsync in another function as you can pass arguments in through pcall itself. Calling functions with : is just syntactic sugar for supplying the target as the first argument, hence why we pass game.Players through pcall.

This is a wierd problem I’m having. I tried your code but for some reason I am still getting a 2 Failure : 8 success ratio. I appreciate you trying to help however. :blush:

I’m convinced that its an error on Roblox’s side though.

I figured my own error out. What was happening is my pcall was returning an error however it wasn’t the error I wanted it to return.

For example, the error should have been: “Players:GetUserIdFromNameAsync() failed: Unknown user” but wasn’t.

New Code:

local check
	local s, e =pcall(function()
		check = game.Players:GetUserIdFromNameAsync(final)
	end)
	
	if check == nil and e == "Players:GetUserIdFromNameAsync() failed: Unknown user" then
		return final
	end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.