Confused by get_the_terms to use in a new wp_query

$terms is an array of terms, so PHP doesn’t know what you mean when you say $terms->slug.

With foreach, you’re iterating through this array. If you only care about the first element, you can simply use $slug = $terms[0]->slug;. This will get you in trouble when there are no terms, though, so you will want to make sure you only operate that if there are terms, with something like

$queryparams = array("post_type" => "mycpt");
if(count($terms)) {
    $slug = $terms[0]->slug;
    // modifiy your queryparams here
    $queryparams["tax_query"] = ...
}

error code: 523