Increase Variable by random amount when using Attack skills[Semi-Solved]

Hello!
I'm mainly an artist and not a programmer, so I got stumped when trying to use a script call in my attack skill's damage formula and it didn't work.

Basically, I want most skills to increase a variable based on which actor is using that skill by a random amount (1-3 currently).
I've been using iterations of this code in the attack skill's damage formula:
JavaScript:
a.atk - b.def; if (a.actorId() == 1)  {var oldValue = $gameVariable.Value(42); $gameVariables.setValue(42,oldValue+Math.randomInt(3)+1);} else {var oldValue = $gameVariable.Value(62); $gameVariables.setValue(62,oldValue+Math.randomInt(3)+1);}

However, it doesn't increment the specified variables at all. I've tested this code outside of battle and it works fine, so I'm not sure what I'm doing wrong.
Any help would be appreciated! 😅

Edit:
I also previously had it at:
JavaScript:
a.atk - b.def; if (a.actorId() == 1)  {$gameVariables.setValue(42,$gameVariable.Value(42)+Math.randomInt(3)+1);} else { $gameVariables.setValue(62,$gameVariable.Value(62)+Math.randomInt(3)+1);}
It didn't work that way either.

Edit 2:
So I didn't figure out how to make the code work, so I used a work-around.
I made separate "attack" skills for each actor that call common events that add to the variable when used.
I changed the actor's attacks by using YEP_WeaponUnleash, which allows you to replace attack and guard skills with other skills.
You've misspelled some of the commands ($gameVariables is plural!) and used the wrong case (it's value and setValue - one has an uppercase V, the other is lowercase). I can't see any other errors.

I will also note that this skill will always deal 0 damage if used by an enemy, because you're calling actorId() which doesn't exist if a is an enemy. If you need it to work for enemies, there is a workaround.

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/increase-variable-by-random-amount-when-using-attack-skills-semi-solved.123909/