How to Tax only on selling tokens using safemoon clone

Hi friends, can someone help me please? im breaking my head almost 3 days trying to solve this error.

i only want taxes when selling on pancakeswap, i manage to active a tax when buying from pancakeswap but when i want to active a tax when selling, error message on testnet pancakeswap appeared.

i already read previus similar topic but i dont see a clear answer. i got this

bool takeFee = true;
if(to == uniswapV2Pair){
if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){
takeFee = false;
takeFee = false;

if i change "if(from == uniswapV2Pair)" i got buying taxes, but if i changed it right, get me an error undefined on pancakeswap testnet, metamask even doesnt open.

Any help please? i almost did everything i can think