I've recently started using TokenMod and a new script to change all the tokens in a new game to set the token bars to my preferred attributes but I'm getting an error because some monsters have NaN in their passive_wisdom (that's my guess on why it crashes as that is what bar 2 value is set to). I can use " !fix-bars" to change individual tokens that don't give this error but I'm unable to use " !fix-bars --all" to change 5,000 or so tokens all at once. How can I fix this? Any help would be appreciated! Here's the code I'm using: on('ready',()=>{ const attr = (c,n) => (findObjs({ type: 'attribute', characterid: c.id, name: n })[0]||{get:()=>0}); let characters = {}; const fixToken = (t) => { let c = getObj('character',t.get('represents')); if(c){ let npc = (attr(c,'npc').get('current')>0); let ac = attr(c, (npc ? 'npc_ac' : 'ac')); let wis = attr(c,'wisdom_mod'); let per_skill = attr(c,'perception_prof'); let per_base = attr(c,'npc_perception_base'); let senses = (`${attr(c,'npc_senses').get('current')}`.match(/passive\s+perception\s+(\d+)/i)||[0,0])[1]; let hp = attr(c,'hp'); let pb = attr(c,'pb'); let pw = attr(c,'passive_wisdom'); let passivePerception = 10 + (npc ? parseInt(per_base.get('current')) : (parseInt(wis.get('current')) + parseInt(((`${per_skill.get('current')}`.length>0) ? pb.get('current') : 0)))); t.set({ bar1_link: ( npc ? '' : (ac ? ac.id : 'sheetattr_ac' )), bar2_link: (npc ? '' : (pw ? pw.id : 'sheetattr_passive_wisdom')), bar3_link: ( npc ? '' : hp.id), bar1_value: ac.get('current'), bar2_value: (parseInt(senses) || passivePerception), bar3_value: (npc ? hp.get('max') : hp.get('current')), bar1_max: '', bar2_max: '', bar3_max: hp.get('max') }); let p = getObj('page',t.get('pageid')); let scale = parseFloat(p.get('snapping_increment')); if( !characters.hasOwnProperty(c.id) && c.get('name') === t.get('name')) { let w = parseInt(t.get('width')); let h = parseInt(t.get('height')); if(scale<1){ let mod = 1/scale; t.set({ height: Math.floor(h*mod), width: Math.floor(w*mod) }); } setDefaultTokenForCharacter(c,t); if(scale<1){ t.set({ height: h, width: w }); } characters[c.id] = true; } } }; on('chat:message', (msg) => { if('api'===msg.type && /^!fix-bars\b/i.test(msg.content) && playerIsGM(msg.playerid)) { let args = msg.content.split(/\s+/).map(s => s.toLowerCase()); let who = (getObj('player',msg.playerid)||{get:()=>'API'}).get('_displayname'); let workQueue = {}; if(args.includes('--all')){ workQueue = findObjs({type:'graphic'}); } else if(msg.selected){ workQueue = msg.selected .map(o=>getObj('graphic',o._id)) .filter(g=>undefined !== g) ; } else { sendChat('Fix Bars', `/w "${who}" <div>Select one or more tokens to fix bar mappings on, or use <code>!fix-bars --all</code> to fix bar mappings on all tokens in the game.</div>`); return; } let count = 0; let timeMark = Date.now(); const drainQueue = ()=>{ let t = workQueue.shift(); if(t){ fixToken(t); ++count; if((Date.now()-timeMark)>5000){ timeMark = Date.now(); sendChat('Fixing Tokens',`/w gm ...${count}`); } setTimeout(drainQueue,0); } else { characters = {}; sendChat('Fixing Tokens',`/w gm Finished Fixing Tokens`); } }; sendChat('Fixing Tokens',`/w gm Fixing ${workQueue.length} Tokens`); drainQueue(); } }); });