Collections permissions are fine but my Velo dropdown code is not working on live site

Product:
Wix Editor

What are you trying to achieve:
I am trying to populate a dropdown from a field in a collection and filter based on that. Preview works fine as intended. I also have a search working on preview, not on live. What could be the reason beyond the collection permissions?

What have you already tried:
My collection permissions are available to everyone.

Additional information:
Code:

import wixData from 'wix-data';

$w.onReady(() => {
  // Get the dataset connected to the repeater
  const dataset = $w('#teamDataset');
  console.log("Dataset referenced:", dataset);

  // Query distinct locations from the Team collection for the Location filter
  wixData.query("Team")
    .distinct("location")
    .then((results) => {
      let uniqueLocations = results.items;
      let locationOptions = [{ "value": "", "label": "All Locations" }];

      uniqueLocations.forEach((location) => {
        locationOptions.push({ "value": location, "label": location });
      });

      $w('#locationDropdown').options = locationOptions;
      console.log("Dropdown populated with locations.");
    })
    .catch((err) => {
      console.error("Error fetching distinct locations: ", err);
    });

  // Add event listeners for search input and location dropdown
  $w('#searchInput').onInput(() => {
    applyFilters(); // Trigger search as the user types
  });

  $w('#searchInput').onKeyPress((event) => {
    if (event.key === "Enter") {
      applyFilters(); // Trigger search when the user presses Enter
    }
  });

  $w('#locationDropdown').onChange(() => {
    applyFilters(); // Trigger filtering when a location is selected
  });

  // Function to apply filters for location and search text
  function applyFilters() {
    const selectedLocation = $w('#locationDropdown').value;
    const searchQuery = $w('#searchInput').value;

    let filter = wixData.filter();

    // Apply location filter if a location is selected
    if (selectedLocation) {
      filter = filter.eq("location", selectedLocation);
    }

    // Apply search filter to both name and location fields (case-insensitive)
    if (searchQuery) {
      const searchFilter = wixData.filter()
        .contains("title", searchQuery)
        .or(wixData.filter().contains("location", searchQuery));

      // Combine the search filter with the location filter
      filter = filter.and(searchFilter);
    }

    // Apply the combined filter to the dataset
    dataset.setFilter(filter)
      .then(() => {
        console.log(`Filter applied: location = "${selectedLocation}", search = "${searchQuery}"`);
      })
      .catch((err) => {
        console.error("Error applying filter:", err);
      });
  }
});