Transaction invalid: some outputs that it attempts to spend have been already spent or are no longer valid.
It's a strange warning, it's the first time I've heard of it, how can it happen?
How can you or the person who wants to scam you make this invalid transaction?
when he uses a wallet support RBF, you will get RBF flag error.
Not necessarily... you might get a "warning" that the incoming transaction is marked as "RBF enabled"... but it won't necessarily stop you from trying to spend those coins. For a lot of wallets, they are considered the same as any other "unconfirmed" coins.
How can you send and get this error?
The error is caused because the "UTXOs" (ie. Outputs from previous transaction(s)) that the current transaction is attempting to use as inputs are:
1. "already spent" - which means another transaction that was using those same UTXOs has already been confirmed in a block and the UTXO is therefore no longer available to be spent as you can't spend the same money twice!
or
2. "no longer valid" - which means that one or more parent transactions is no longer considered a valid transaction, so any UTXOs that they created are likewise no longer valid. This is most likely because it was replaced before it was confirmed by using RBF or a double spend attack.
Because the network is quite overloaded at the moment... it's fairly "easy" to create a low fee rate transaction that is not likely to get confirmed any time soon... and then replace it using RBF with a much larger fee rate transaction. So, it can be possible to trick people into thinking they've been paid, and then redirect the funds elsewhere using the high fee rate transaction before the original low fee rate transaction gets confirmed.
If you are selling or trading NEVER send items/money etc until the receiving transaction has at least ONE confirmation...