$task = new PingTask($this, $player); $id = $task->getTaskId(); $this->getScheduler()->cancelTask($id); why it cant cancel task?
the task is not scheduled, the default TaskId is -1 (iirc), you must schedule it first, then get the task id
PHP: $this->getScheduler()->scheduleRepeatingTask(new PingTask($this, $player), 5); schedule with this code?
Firstly you should add property. PHP: /** * @var array */public $taskId = []; After add task id to list when you call task. PHP: $this->taskId[$player->getName()] = $this->getScheduler()->scheduleRepeatingTask(new PingTask($this, $player), 5)->getTaskId(); For cancelling task for specific player. PHP: if (isset($this->taskId[$player->getName()])) { $this->getScheduler()->cancelTask($this->taskId[$player->getName()]); unset($this->taskId[$player->getName()]);}