Unbanning a player with the new Ban API

When trying to unban a player with their UserID, with the new BAN API, it display this error

image

Code Snippet:

Event.OnServerEvent:Connect(function(admin, ID, reason)
	local PlayerID = tonumber(ID)
	local PlayerName = Players:GetNameFromUserIdAsync(PlayerID)

	print(admin.Name .. " is unbanning; " .. PlayerName .. " ("..PlayerID..")")

	local success, err = pcall(function()
		Players:UnbanAsync(PlayerID)
	end)

	if success then
		print("Successfully unbanned UserID:", PlayerID, "Reason:", reason)
	else
		warn("Failed to unban UserID:", PlayerID, "-", err)
	end
end)

trying to make it unban the player when they are banned through the new Ban API

The UnbanAsync method does NOT take in numbers, but a dictionary. A good way to call it would be (from the documentation)

Players:UnbanAsync({
		UserIds = {player.UserId, 789},
		ApplyToUniverse = false
	})

You check the UnbanConfigType for the exact format, but this method (:UnbanAsync) is more suited for bulk unbans unlike Players.UnbanAsync

Edit: It’s also mentioned in the syntax that the service is not live

1 Like

Make sure whenever your adding the Players ID its always in a dictionary, even if its only one item. A quick way to fix that, I think, would to replace the PlayerID with {PlayerID}. So it would look a bit something like:

local success, err = pcall(function()
	Players:UnbanAsync({PlayerID})
end)