You’re nearly there…
The ‘query_posts’ function is only intended to return posts (and other post types) so this will not work for roles. The line $roles = ...
is likely the cause of your error
instead it should just be:
$roles = $wp_roles->get_names();