const ranks = [
  { kills: 5, title: '§eRookie Killer' },
  { kills: 15, title: '§6Trained Slayer' },
  { kills: 30, title: '§bFearsome Fighter' },
  { kills: 50, title: '§cWarlord' },
  { kills: 100, title: '§4Legendary Executioner' }
]

ServerEvents.tick(event => {
  if (event.server.tickCount % 40 !== 0) return // Every 2 seconds

  const scoreboard = event.server.scoreboard
  const players = event.server.players

  players.forEach(player => {
    const current = scoreboard.getPlayerScore(player, 'kills') || 0
    const rankData = player.persistentData

    ranks.forEach(rank => {
      if (current >= rank.kills && !rankData[`rank_${rank.kills}`]) {
        player.runCommandSilent(`title ${player.username} title {"text":"${rank.title}","color":"gold","bold":true}`)
        player.tell(`§bYou’ve reached the rank: ${rank.title}`)
        rankData[`rank_${rank.kills}`] = true
      }
    })
  })
})
