States not being properly applied to enemies? (Buff/States, Auto Passive States)

Hello. As the title implies, I'm trying to create a weapon that has a chance to apply a negative state onto an enemy whenever a physical attack is used, but it's not working quite right.
So, first, I creative a passive state called "freeze chance" using yanfly's auto passive state, and set that passive state to the weapon in question. Then, I used this code so that the freeze state can be applied to enemies that are hit with physical attacks:
<Custom Establish Effect>
\\ I set the chance rate to 99 for the sake of testing
ChanceRate = 0.99;
if (this.isPhysical() && result.isHit() && Math.random() < ChanceRate) {
\\ State 12 is the frozen state
target.addState(12);
}
</Custom Establish Effect>
Then, I tested it in battle a few different ways. Hitting enemies with the default attack didn't work at all. Then, I tested it using a physical skill that targets all enemies, and the state was applied to all enemies except for the first one (Enemy A).
I know that I could just add an attack state to the weapon, but I want all physical attacks to have a chance to inflict freeze, not just the attack command.
Try this instead~
Code:
<Custom Establish Effect>
var ChanceRate = 1;  // 100% chance
if (this.isPhysical() && target.result().isHit() && Math.random() < ChanceRate) {
  target.addState(12);  // add frozen state
}
</Custom Establish Effect>
Try this instead~
Code:
<Custom Establish Effect>
var ChanceRate = 1;  // 100% chance
if (this.isPhysical() && target.result().isHit() && Math.random() < ChanceRate) {
  target.addState(12);  // add frozen state
}
</Custom Establish Effect>
That worked! Thank you so much! ^_^

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/states-not-being-properly-applied-to-enemies-buff-states-auto-passive-states.115234/