Problem with a var and maybe yanfly plugin class base parameter

I'm a beginner at coding so I might be doing something wrong at many parts hahaha. But I used yanfly class plugin http://www.yanfly.moe/wiki/Class_Base_Parameters_(YEP) and there is the option to code inside a class to make the gain more unique.​

I wanted to make random gains of hp per level from 1 to 6 so I wrote this.​

Code:
<Custom maxhp Formula>
value = Math.ceil(Math.random() * 5 + 1)
</Custom maxhp Formula>

value is the MaxHP, he gets a number from 1 to 6, ok it obviously works, but now every level he will generate a random number to the maxhp as expected.
I cant put the code "level" multiplying anything inside there or the randomly generated number from levels before would be forgotten. No problem still expected. I came up with a solution which sounded good in my mind, "+=" should add the current value before dding a new one, but it doesn't work, the + is just ignored. No problem I will find another way.
I tried creating a var inside there, but it didn't work. (Also I wanted the first level to start with at least 30 hp)

Code:
<Custom maxhp Formula>
if(this.level === 1){
    value = Math.ceil(Math.random() * 5 + 30);
    var bunda = value;
    } else {
    value = bunda + (Math.floor(Math.random() * 5 + 1));
    bunda = value;
    }
</Custom maxhp Formula>

Nope, it doesn't work, I guessed it was because this var isn't keeping the value it's storing, so...

I'm a bit lazy I thought what if I create a var to keep the value.

I wrote a plugin, put in my game and inside there is only this "var bunda;"

This means that there is a var called bunda in my game, ok. Then I wrote this:

Code:
<Custom maxhp Formula>
    if(this.level === 1){
    value = Math.ceil(Math.random() * 5 + 30);
    bunda = value;
    } else {
    value = bunda + (Math.floor(Math.random() * 5 + 1));
    bunda = value;
    }
</Custom maxhp Formula>

First level is ok as one would expect, but whenmy character levels up some weird numbers are thrown into the mix and the character sometimes gets +10 HP or +8 when there should be only 1 to 6.

Why does this happen?

EDIT1: Apparently this idea I had isn't good either because the character is gaining MHP everytime he changes the map. So my guess is that Yanfly pugin is applying the hp formula everytime the character is loaded.

EDIT2: Does the character get loaded everytime he changes scene? That's why when chaging scenes it keeps adding up. If I'm correct then the solution is just calculate the RNG variation outside the character and apply only the result when he levels up. This might work, but since I'm no expert in coding it might not be pretty.

(is there any way for me to move this to javascript support? I didn't notice there was a forum for javascript support)
Hah. Everything works now, instead of learning how to make a plugin (which was kinda hard for me being a beginner and all) I found this plugin by Yanfly: http://www.yanfly.moe/wiki/Level_Up_Growth_Effects_(YEP)

The rest was easy, but just to have a solution for a lost soul that might search here.

This is how I did my random stat gain every level:

Code:
<Custom Level Up Effect>
this.addParam(0, Math.round(Math.random() * 4) + 1);
</Custom Level Up Effect>

Pretty simple, right? Now every level the character will gain from 1 to 5 of HP.

Original thread: https://forums.rpgmakerweb.com/threads/problem-with-a-var-and-maybe-yanfly-plugin-class-base-parameter.121743/