(YEP_BuffsStatesCore) Help with State Effect

Hello!
In my project, I created an Ability that increases the User's 'Attack' Parameter by using his 'Luck' Parameter. It does so by applying a State to the User (i'll call it 'BonusLuk'), which is checked for in the damage formula to determine if to apply the Bonus or not.
And along with that, i created a Passive Ability that would give half of this bonus to all your party members whenever you use the Ability (it would do that by equipping the State 'Share_BonusLuk').
To do that, i made a simple check (with Yanfly's ActionSequencePack):

Spoiler: code
add state 'BonusLuk': user
if(user.isStateAffected('Share_BonusLuk'))
{
change variable 2 = Math.floor(($gameActors.actor(1).param(7) - 10) / 4)
}

This way, if the user has the Passive Ability equipped, it saves the bonus in a Variable, which is then used by other allies' damage formula.
Then I added to the State 'BonusLuk' a Notetag:

Spoiler: code
<Custom Remove Effect>
$gameVariables.setValue(2, 0);
user.refresh();
</Custom Remove Effect>


<Custom Leave Effect>
$gameVariables.setValue(2, 0);
user.refresh();
</Custom Leave Effect>


This would, theoretically, reset the Bonus given by the ability when either the State's Turn Count reaches 0 or the State is forcibly removed (like at the end of the battle). And it works in both those cases!
The only problem is that the Bonus seems to not be removed in the case when the User dies while still having the State on. In fact, the allies keep the bonus given by their ally for the rest of the fight!
Am i doing something wrong? Thanks in advance!

Edit: Apparently Yanfly had exactly the answer to my problem. If someone reading this is having the same issue written in this post, check YEP_X_StateCategories.

Original thread: https://forums.rpgmakerweb.com/threads/yep_buffsstatescore-help-with-state-effect.114389/