Get Average Party Level from script call.

I am trying to check the average party level through an event/script call.
This is what I have so far, I rarely mess with scripts and especially in RMMV so this may be on the right track or complete incorrect (found it from a past post in vx and tweaked it some but stilll doesnt work)

Code:
avg_lvl = 0

$gameParty.members().each {|actor| avg_lvl += actor.level}

avg_lvl /= $gameParty.members().length

$gameVariables.setValue(80, avg_level)
Code:
let average_lvl = 0;
for(p=0; p<$gameParty.members().length; p++){
   average_lvl += $gameParty.members()[p].level;
}
average_lvl /= $gameParty.members().length;
$gameVariables.setValue(1, average_lvl);

got it solved from someone in discord if anyone else needs this info.

Original thread: https://forums.rpgmakerweb.com/threads/get-average-party-level-from-script-call.145938/