
EDITED After Victor's comments. :) The following error has occurred today after I wrote the following code which is based on another, much more involved script. The item that is causing the error is the for statement. I ran into this error today, but the more involved script I referred to was working perfectly until today and it also throws the same error. Both the code below and the more complex one run fine when one or three tokens are selected. However, when I select all tokens, the error raises its head. A screen shot of the error message: Here is my code that I am wanting to develop into something a little more complex (I want to copy selected tokens to another page in the same location and change their tint colour or add one of the coloured token status). The error is occurring in the For loop2nd or 3rd line. It did not do this until now. What I did do is "Let" the same variable names, except for the two tint colours (tintfriendly and tintenemy). I figured because they were in different scripts and declared following different If statement that there would not be any confusion. Could this be what is messing things up? on ('chat:message', function(msg) { let chatcommand = msg.content.trim().toLowerCase(); let sender = 'player|' + msg.playerid; if(msg.type == 'api' && chatcommand.startsWith('!copyunitstogm')) { let selected = msg.selected; let tintfriendly = "#cc0000"; let tintenemy = "#0000ff"; let ctr; //There will definitely be one selected! let selectedcount = 0; //log("---Start---"); if (selected === undefined) { sendChat(sender,"**=============**<br>**Copy to GM Map Process**<br>" + "**Error:** *No units are selected!*<br>Select a unit " + "and try again.", null, {noarchive:true}); return; } for (ctr=0; selected[ctr] !== undefined; ctr++) { selectedcount++; let token = getObj("graphic",selected[ctr]._id); //Assigns the token object to token //log("Name: " + token.get("name")); sendChat(sender, selectedcount + " " + token.get("name"), null, {noarchive:true}); let charid = token.get("represents"); //Determins if there is a character ID associated //log("charid: [" + charid + "]"); let unit = getObj("character", charid); } //log(selectedcount); sendChat(sender, "**Selected tokens: " + selectedcount +"**", null, {noarchive:true}); } }); As I mention in my title, this has worked beautifully before in the more complex script. Suddenly, tonight both are not. I don't believe I've changed anything at all. Can anyone please help? -- Tim