In short
GetUserIdFromNameAsync looks up a username on Roblox and returns the user ID. When no account has that name, it throws Unknown user, and because it throws, an unprotected call stops your whole script, which is how one bad ban or give command breaks an admin system. Wrap every lookup in pcall, tell the person who typed it, and look players in the server up by name with Players:FindFirstChild instead.
What the message means
ServerScriptService.AdminCommands:18: Players:GetUserIdFromNameAsync() failed: Unknown user
Usernames and display names are different. Many players show a display name in game that is not their username, and the lookup only knows usernames.
It is a web request, so it can also fail for other reasons, such as a network error. The same pcall covers both.
Causes and fixes
Two things cause this error in practice. Each one below has the smallest code that triggers it, then the fix.
A typed name is looked up without pcall
An admin types /ban Bilderman. The lookup throws and the command script stops.
local Players = game:GetService("Players")
local function getUserId(name: string): number
return Players:GetUserIdFromNameAsync(name)
end
print(getUserId("ThisUserDoesNotExist12345"))
Wrap it in pcall and return nil when it fails, so the caller can reply "No user named ...".
local Players = game:GetService("Players")
local function getUserId(name: string): number?
local ok, result = pcall(function()
return Players:GetUserIdFromNameAsync(name)
end)
if ok then
return result
end
warn("No user named", name)
return nil
end
print(getUserId("ThisUserDoesNotExist12345"))
The player is in the server anyway
Commands like kick, give or teleport target someone in the same server. A web lookup is slower and fails on display names.
local Players = game:GetService("Players")
local function kickByName(name: string)
local userId = Players:GetUserIdFromNameAsync(name)
local target = Players:GetPlayerByUserId(userId)
if target then
target:Kick("Removed by an admin")
end
end
Search the players in the server by username or display name. No web request, no Unknown user.
local Players = game:GetService("Players")
local function findPlayer(text: string): Player?
local wanted = string.lower(text)
for _, player in Players:GetPlayers() do
if string.lower(player.Name) == wanted or string.lower(player.DisplayName) == wanted then
return player
end
end
return nil
end
local function kickByName(name: string)
local target = findPlayer(name)
if target then
target:Kick("Removed by an admin")
end
end
kickByName("Nobody")
Fix it in your place
Paste the error, RoCode fixes it in your place
Copy the line from Output and paste it here. RoCode opens the script it names in the place you have open in Studio, works out which of the causes above it is, and edits the code there instead of handing you a snippet to paste.
RoCode is an AI agent for Roblox Studio: it reads the scripts in the place you have open, finds the line and edits it there, and every change is an undo point. It runs on Windows or macOS with a desktop browser. Free to start, with free credits every day.
How to find the line that causes it
- Open Output (Window menu, or the Script tab), clear it with Ctrl+K (⌘K on Mac), and press Play.
- Find the first red line. It starts with the script's place in the Explorer and the line number, such as
ServerScriptService.Shop:12:. - Click the red line. Studio opens that script with the cursor on the failing line.
- Read the lines between
Stack BeginandStack Endunder it: they list the calls that led there, newest first, so you can see which function called the broken one. - Still not sure which value is wrong? Add
print(typeof(x), x)just above the line, or set a breakpoint on it and read the values in the Watch window.
Questions
Does GetUserIdFromNameAsync work with display names?
No, only with usernames. Search the players in the server for display names, as in the second fix.
Does it work in Studio?
Yes. It is a web request, so Studio needs to be online, and Roblox may slow down many requests in a short time.
How do I ban someone who is not in the server?
Look up their user ID with the pcall version, then use Players:BanAsync with that ID. Show the admin a clear message when the name does not exist.
Can RoCode fix it?
Yes. Paste the Output line into RoCode. It wraps the lookups in your place in pcall and switches in-server commands to a player search.
Sources and further reading
How the code was checked: every block marked Fixed passes Luau's strict type checker against Roblox's API definitions (luau-lsp, 12 November 2026), and every block marked Breaks compiles and fails only when it runs. The message wording was checked against the strings in Roblox Studio itself (macOS build installed on 12 November 2026) on 12 November 2026. A type check catches misspelt APIs and wrong types, not game logic, so playtest in Studio before you publish.