Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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/

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