Basically, you have a swing animation of some sort and during that animation, you create a hitbox object where the sword is slashing. There's not any major complicated programming to it. It's kind of like creating a still bullet. So you draw a rectangular sprite. Then create an object and give it the sprite. When you slash the sword, make the hitbox sprite appear in front of the player at the desired position. Delete the hitbox after the slash animation is over. Then make it so enemies react to touching the hitbox.
If your player moves while he/she slashes, you'll have to make the hitbox stay with the player by setting it to the players position and then adding your desired offset so that it's always in front of the player.
If you don't know what I mean, here's a tutorial from Shaun Spalding:
GameMaker Studio 2: Melee Attacks Tutorial
EDIT: Watching Shaun's video again, he uses a more advanced approach from what I said.