Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

315
Views
I cant stop my interval and neither clearInterval() work;

I've made simple userscript for the game https://zty.pe/, The bot work on my modified version of the game, I'm trying to make it whenever I click "F" it starts running , but stops when I click " C ", the loop works normally after clicking C and it doesnt stop.

document.addEventListener('keydown', (e) => {
  key = e.keyCode
  if(key == 70){
  var zTypeBotAlphaChars = "abcdefghijklmnopqrstuvwxyz";
  var zTypeBotCharToType = 0;
  ztypebot = setInterval(function() {
  ig.game.shoot(
  zTypeBotAlphaChars.charAt(zTypeBotCharToType));
  }
  , 10);
  }
})


document.addEventListener('keydown', (e) => {
  if(e.keyCode == 67){
    clearInterval(ztypebot, 10);
  }
})
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Try adding window. before ztypebot interval to make it a global function:

document.addEventListener('keydown', (e) => {
  key = e.keyCode
  if(key == 70){
  var zTypeBotAlphaChars = "abcdefghijklmnopqrstuvwxyz";
  var zTypeBotCharToType = 0;
  window.ztypebot = setInterval(function() {
  ig.game.shoot(
  zTypeBotAlphaChars.charAt(zTypeBotCharToType));
  }
  , 10);
  }
})


document.addEventListener('keydown', (e) => {
  if(e.keyCode == 67){
    clearInterval(window.ztypebot, 10);
  }
})
about 4 years ago · Juan Pablo Isaza Report

0

Your ztypebot variable is local in each function, you need to define it outside like so:

let ztypebot;

document.addEventListener('keydown', (e) => {
  ...
  ztypebot = setInterval(function() {
    ...
  }
})


document.addEventListener('keydown', (e) => {
  if(e.keyCode == 67){
    clearInterval(ztypebot, 10);
  }
})
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!