Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I properly get rid of the HTTP error when getting name from user ID?

Asked by
funyun 958 Moderation Voter
8 years ago

Long story short, I don't want this to pop up:

21:45:04.347 - Players:GetNameFromUserId() failed because HTTP 400 (HTTP/1.1 400 Invalid userId)

Here's what I have in the script:

function dostuff(task)
    local name = game:GetService("Players"):GetNameFromUserIdAsync(task)
    print(name)
end

I tried pcalling, but that doesn't give me any names:

function dostuff(task)
    local good_to_go, name = pcall(function()
        game:GetService("Players"):GetNameFromUserIdAsync(task)
    end)

    if good_to_go then print(name) end
end

I don't know how to get around this. Any help?

1 answer

Log in to vote
0
Answered by 8 years ago
function dostuff(task)
    local good_to_go, name = pcall(function()
        game:GetService("Players"):GetNameFromUserIdAsync(tonumber(task))
    end)

    if good_to_go then print(name) end
end

Well, there's a numbervalue, and an Intvalue. task is a numbervalue, and userIDs are a intvalue. try using tonumber to solve this problem/

Ad

Answer this question