Copied Dropdown Sort Function not working from one site to another

I’ve been using Wix to create a website and the one aspect I wanted that Wix doesn’t have is the ability for users to sort datasets (displayed in this case in a table) in real time using an element, it requires a java script (which I confess I am not brilliant with).

So after a lot of googling I found a script that worked. A friend who also uses Wix was very impressed and asked me to add the same to his site, he gave me the right perms to edit his site and CMS data and I went to work. However, despite following the exact same steps I did for my site, I cannot get this sort function to work on his site. Below is the script for the dropdown box I’m using to trigger the sort. This script works perfectly on my site and the only difference is the Selection Names and the field IDs.

import wixData from "wix-data";


export function dropdown1_change_(event) {

if(event.target.value === 'K/D'){
console.log('K/D clicked');
$w('#dataset4').setSort(wixData.sort().descending("kD").descending("avgScore"));
}

if(event.target.value === 'Avg Score'){
console.log('Avg Score clicked');
$w('#dataset4').setSort(wixData.sort().descending("avgScore").descending("kD"));
}

if(event.target.value === 'Wins'){
console.log('Wins clicked');
$w('#dataset4').setSort(wixData.sort().descending("avgScore").descending("avgScore"));
}

if(event.target.value === 'Total Kills'){
console.log('Total Kills clicked');
$w('#dataset4').setSort(wixData.sort().descending("totalKills").descending("avgScore"));
}

if(event.target.value === 'Total Deaths'){
console.log('Total Deaths clicked');
$w('#dataset4').setSort(wixData.sort().descending("totalDeaths").descending("avgScore"));
}

if(event.target.value === 'Total Score'){
console.log('Total Score clicked');
$w('#dataset4').setSort(wixData.sort().descending("totalScore").descending("avgScore"));
}
}

When testing, the console does not register the clicks either as it does on my site. Any assistance would be greatly appreciated.

Many Thanks

import wixData from "wix-data";

$w.onReady(()=>{
  $w('#dataset4').onReady(()=> {
    $w('#dropdown1').onChange((event)=>{console.log(event.target.id + '-clicked');
      if(event.target.value === 'K/D')			{sortData('kD', 'avgScore');}
      if(event.target.value === 'Avg Score')	{sortData('avgScore', 'kD');}
      if(event.target.value === 'Wins')			{sortData('avgScore', 'avgScore');}
      if(event.target.value === 'Total Kills')	{sortData('totalKills', 'avgScore');}
      if(event.target.value === 'Total Deaths')	{sortData('totalDeaths', 'avgScore');}
      if(event.target.value === 'Total Score')	{sortData('totalScore', 'avgScore');}
    });
  });
});

function sortData(val_1, val_2) {
	$w('#dataset4').setSort(wixData.sort().descending(val_1).descending(val_2));
}