I don’t think you can do that natively. If you’re telling Shopify to “continue selling when out of stock” it will sell an infinite amount.
If you want to only sell X units, untick “continue selling” and just set the stock level to X. And then when it sells out, it’ll actually be sold out and stop selling.