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,
-- 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.
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