Help with some code for a game

hi so I am making a game where you can press a button to interact with someone and I tried this code and it is not working. If anyone has any ideas please help.

function keyPressed(key){
if(this.hits(player)) {
    this.gotoAndStop("press");
    
if(key === "space"){
    gotoAndStop(6);
}
} else {
    this.gotoAndStop(1);
}

}

Share me the wick file and I’ll see what i can do

function keyPressed(key){
if(this.hits(player)) {
    this.gotoAndStop("press");
    
if(key === "space"){
    gotoAndStop(6);
}
} else {
    this.gotoAndStop(1);
}

}

You’re forgetting something here, preventing the code from working. Let me fix it for you:

function keyPressed(key){
if(this.hits(player)) {
    this.gotoAndStop("press");
}
if(key === "space"){
    gotoAndStop(6);
}
} else {
    this.gotoAndStop(1);
}

}

ah, nevermind.

Oh, I already fixed it, but this code will help with something else, so thank you!