Looking into the Types it seems like playerIds only returns for users inside the server.
As this is an unbanning script it’s highly unlikely that the user your unbanning is going to be inside the server so there is a few things you’d need to modify within the Cmdr Types.
Inside your Cmdr > Types folder you should see the module called “PlayerId”, update the source code of that module with what’s below, this will allow for a mixture of users in-game and users not in-game to be added to the list.
What was happening before is the ID you were trying to unban wasn’t in the server so it wasn’t adding them to the list.
local Util = require(script.Parent.Parent.Shared.Util)
local Players = game:GetService("Players")
local nameCache = {}
local function getUserId(name)
if nameCache[name] then
return nameCache[name]
elseif Players:FindFirstChild(name) then
nameCache[name] = Players[name].UserId
return Players[name].UserId
else
local fetchedName, username = pcall(Players.GetNameFromUserIdAsync, Players, name)
local fetchedUserId, userid = pcall(Players.GetUserIdFromNameAsync, Players, username)
if userid ~= tonumber(name) then
return nil
end
nameCache[username] = userid
return userid
end
end
local playerIdType = {
DisplayName = "Full Player Name";
Prefixes = "# integer";
Transform = function (text)
local findPlayer = Util.MakeFuzzyFinder(Players:GetPlayers())
return text, findPlayer(text)
end;
ValidateOnce = function (text)
return getUserId(text) ~= nil, "No player with that name could be found."
end;
Autocomplete = function (_, players)
return Util.GetNames(players)
end;
Parse = function (text)
return getUserId(text)
end;
Default = function(player)
return player.Name
end;
}
return function (cmdr)
cmdr:RegisterType("playerId", playerIdType)
cmdr:RegisterType("playerIds", Util.MakeListableType(playerIdType, {
Prefixes = "# integers"
}))
end
This would be the updated unban script itself, regardless of the issue above even if the script above did allow for users to be added to the list if they weren’t in-game unbanAsync requires the Parameters to be wrapped in a table, with unbanAsync you can also bulk unban so you don’t need to send 25 different unbanAsync request to unban 25 users instead you can use the original list and just unban all 25 of those users at the same time.
If it errors on a particular user according to the PlayerService docs for BanAPI it’ll join all the errors together separated by a comma.
For example, if this method is invoked for five UserIds: {1, 2, 3, 4, 5} and requests for users 2 and 4 fail then the following error message appears: HTTP failure for UserId 2: Timedout, HTTP 504 (Service unavailable) failure for UserId 4: Service exception.
I’ve utilized that with the CommandContext | Reply to differentiate the error messages and the final request.
local PlayerService = game:GetService("Players")
return function (context, Players)
local config: UnbanConfigType = {
UserIds = Players,
ApplyToUniverse = false
}
local success, err = pcall(function()
return PlayerService:UnbanAsync(config)
end)
if not success then
local formatError = string.split(err, ",")
local failedRequest = #formatError
for _, readError in formatError do
context:Reply(readError, Color3.fromRGB(177, 49, 49))
end
return `Unbanned {#Players - failedRequest} player(s), {failedRequest} request failed.`
end
return `Unbanned {#Players} player(s).`
end