Sample crowdsale contracts help

If you're new you should walk through OpenZeppelin Upgrades: Step by Step Tutorial for Hardhat

Then go over the learning material.

This will give you some understanding how to write any function desire.

What you want to accomplish is move ETH into a contract, then the contract dispense tokens. Have that transfer upon receiving ETH in a payable function.