Lua functions always returns empty on query

local nk = require("nakama")


local registered_indexes = {}



function has_value (tab, val)
    for index, value in ipairs(tab) do
        if value == val then
            return true
        end
    end

    return false
end




function get_leaderboard_records_from_floor(context, payload)
    local data = nk.json_decode(payload)
    local name = data.key .. "_" .. data.floor_record

    if not has_value(registered_indexes, name) then
        nk.register_storage_index(name, "leaderboard", data.key, {"floor_number"}, {}, 1000)
        table.insert(registered_indexes, name)
    end

    local query = "+value.floor_number:" .. data.floor_record
    local result = nk.storage_index_list(name, query, data.entries, {})

    return nk.json_encode(result )
end






nk.register_rpc(get_leaderboard_records_from_floor, "get_leaderboard_records_from_floor")

example storage object

{
  "active_trials": [
    "res://resources/trials/honor.tres"
  ],
  "base_stats": [
    {
      "amount": 7,
      "is_modifier": false,
      "resource": "res://resources/stats/max_health.tres"
    },
    {
      "amount": 5,
      "is_modifier": false,
      "resource": "res://resources/stats/physical_attack.tres"
    },
    {
      "amount": 3,
      "is_modifier": false,
      "resource": "res://resources/stats/max_mana.tres"
    },
    {
      "amount": 1,
      "is_modifier": false,
      "resource": "res://resources/stats/total_attacks.tres"
    },
    {
      "amount": 0,
      "is_modifier": false,
      "resource": "res://resources/stats/health.tres"
    },
    {
      "amount": 0,
      "is_modifier": false,
      "resource": "res://resources/stats/energy.tres"
    },
    {
      "amount": 0,
      "is_modifier": false,
      "resource": "res://resources/stats/mana.tres"
    },
    {
      "amount": 0,
      "is_modifier": false,
      "resource": "res://resources/stats/active_armor.tres"
    },
    {
      "amount": 3,
      "is_modifier": false,
      "resource": "res://resources/stats/life_steal.tres"
    }
  ],
  "battle_profile": {
    "active_status_effects": [],
    "modifiers": [],
    "removed_status_effects": [],
    "stats": [
      {
        "amount": 22,
        "is_modifier": false,
        "resource": "res://resources/stats/armor.tres"
      },
      {
        "amount": 5,
        "is_modifier": false,
        "resource": "res://resources/stats/faith.tres"
      },
      {
        "amount": 3,
        "is_modifier": false,
        "resource": "res://resources/stats/physical_attack.tres"
      }
    ],
    "turns": [
      {
        "abilities": [],
        "ability_activation_count": 0,
        "armor_damage_taken": 4,
        "attack_goals": [],
        "attacks": 2,
        "consumed_stacks": [],
        "counter_attacks": 0,
        "dodges": 0,
        "health_damage_taken": 21,
        "health_recovered": 10,
        "kills": 0,
        "misses": 0,
        "multi_attack": false,
        "parries": 0,
        "received_status_effects": [
          {
            "amount": 1,
            "resource": "res://resources/status_effects/silence.tres"
          },
          {
            "amount": 1,
            "resource": "res://resources/status_effects/stun.tres"
          },
          {
            "amount": 1,
            "resource": "res://resources/status_effects/vimblow.tres"
          }
        ],
        "used_ability": false
      },
      {
        "abilities": [
          "res://resources/abilities/drain.tres"
        ],
        "ability_activation_count": 0,
        "armor_damage_taken": 0,
        "attack_goals": [],
        "attacks": 2,
        "consumed_stacks": [
          {
            "amount": 1,
            "resource": "res://resources/status_effects/vimblow.tres"
          }
        ],
        "counter_attacks": 0,
        "dodges": 0,
        "health_damage_taken": 34,
        "health_recovered": 21,
        "kills": 1,
        "misses": 0,
        "multi_attack": false,
        "parries": 0,
        "received_status_effects": [
          {
            "amount": 1,
            "resource": "res://resources/status_effects/vimblow.tres"
          },
          {
            "amount": 1,
            "resource": "res://resources/status_effects/stun.tres"
          }
        ],
        "used_ability": false
      },
      {
        "abilities": [
          "res://resources/abilities/drain.tres"
        ],
        "ability_activation_count": 0,
        "armor_damage_taken": 0,
        "attack_goals": [
          0,
          0,
          0
        ],
        "attacks": 2,
        "consumed_stacks": [
          {
            "amount": 1,
            "resource": "res://resources/status_effects/vimblow.tres"
          }
        ],
        "counter_attacks": 0,
        "dodges": 0,
        "health_damage_taken": 34,
        "health_recovered": 34,
        "kills": 0,
        "misses": 0,
        "multi_attack": false,
        "parries": 0,
        "received_status_effects": [
          {
            "amount": 1,
            "resource": "res://resources/status_effects/vimblow.tres"
          }
        ],
        "used_ability": false
      },
      {
        "abilities": [
          "res://resources/abilities/drain.tres"
        ],
        "ability_activation_count": 0,
        "armor_damage_taken": 0,
        "attack_goals": [
          0,
          0,
          0
        ],
        "attacks": 2,
        "consumed_stacks": [
          {
            "amount": 1,
            "resource": "res://resources/status_effects/vimblow.tres"
          }
        ],
        "counter_attacks": 0,
        "dodges": 0,
        "health_damage_taken": 43,
        "health_recovered": 34,
        "kills": 0,
        "misses": 0,
        "multi_attack": false,
        "parries": 0,
        "received_status_effects": [
          {
            "amount": 1,
            "resource": "res://resources/status_effects/vimblow.tres"
          },
          {
            "amount": 1,
            "resource": "res://resources/status_effects/confusion.tres"
          }
        ],
        "used_ability": false
      },
      {
        "abilities": [],
        "ability_activation_count": 0,
        "armor_damage_taken": 0,
        "attack_goals": [
          0,
          0,
          0
        ],
        "attacks": 2,
        "consumed_stacks": [
          {
            "amount": 1,
            "resource": "res://resources/status_effects/vimblow.tres"
          }
        ],
        "counter_attacks": 0,
        "dodges": 0,
        "health_damage_taken": 42,
        "health_recovered": 0,
        "kills": 0,
        "misses": 2,
        "multi_attack": false,
        "parries": 0,
        "received_status_effects": [],
        "used_ability": false
      }
    ]
  },
  "died": true,
  "equipment": {
    "infinite": false,
    "items": [
      null,
      null,
      {
        "changed_this_frame": false,
        "description_override": "",
        "is_phantom": false,
        "max_rarity": 8,
        "name_override": "",
        "rarity": 2,
        "resource": "res://resources/items/silver_leggings.tres",
        "used": false
      },
      {
        "changed_this_frame": false,
        "description_override": "",
        "is_phantom": false,
        "max_rarity": 8,
        "name_override": "",
        "rarity": 2,
        "resource": "res://resources/items/silver_sabatons.tres",
        "used": false
      },
      {
        "changed_this_frame": true,
        "description_override": "",
        "is_phantom": false,
        "max_rarity": 8,
        "name_override": "",
        "rarity": 3,
        "resource": "res://resources/items/amulet_of_life.tres",
        "used": false
      },
      {
        "changed_this_frame": false,
        "description_override": "",
        "is_phantom": false,
        "max_rarity": 8,
        "name_override": "",
        "rarity": 1,
        "resource": "res://resources/items/hunger_blade.tres",
        "used": false
      },
      {
        "changed_this_frame": true,
        "description_override": "",
        "is_phantom": false,
        "max_rarity": 8,
        "name_override": "",
        "rarity": 1,
        "resource": "res://resources/items/life_seeker.tres",
        "used": false
      },
      null
    ],
    "mode": 0,
    "modification_order": [
      4,
      3,
      2,
      6,
      7,
      1,
      0,
      5
    ],
    "resource": "res://resources/item_containers/equipment.tres",
    "sockets": [
      0,
      1,
      2,
      3,
      4,
      5,
      6,
      6
    ]
  },
  "extra_gold_gain": 0,
  "floor_number": 2,
  "gold_coins": 143,
  "gold_coins_earned": 128,
  "gold_coins_spent": 2394,
  "inventory": {
    "infinite": false,
    "items": [
      {
        "changed_this_frame": false,
        "description_override": "",
        "is_phantom": false,
        "max_rarity": 8,
        "name_override": "",
        "rarity": 3,
        "resource": "res://resources/items/leather_helmet.tres",
        "used": false
      },
      {
        "changed_this_frame": false,
        "description_override": "",
        "is_phantom": false,
        "max_rarity": 8,
        "name_override": "",
        "rarity": 1,
        "resource": "res://resources/items/leather_helmet.tres",
        "used": false
      },
      {
        "changed_this_frame": false,
        "description_override": "",
        "is_phantom": false,
        "max_rarity": 8,
        "name_override": "",
        "rarity": 3,
        "resource": "res://resources/items/iron_dagger.tres",
        "used": false
      },
      {
        "changed_this_frame": false,
        "description_override": "",
        "is_phantom": false,
        "max_rarity": 8,
        "name_override": "",
        "rarity": 0,
        "resource": "res://resources/items/amulet_of_life.tres",
        "used": false
      },
      {
        "changed_this_frame": false,
        "description_override": "",
        "is_phantom": false,
        "max_rarity": 8,
        "name_override": "",
        "rarity": 1,
        "resource": "res://resources/items/iron_dagger.tres",
        "used": false
      },
      {
        "changed_this_frame": false,
        "description_override": "",
        "is_phantom": false,
        "max_rarity": 8,
        "name_override": "",
        "rarity": 0,
        "resource": "res://resources/items/leather_chestplate.tres",
        "used": false
      },
      {
        "changed_this_frame": false,
        "description_override": "",
        "is_phantom": false,
        "max_rarity": 8,
        "name_override": "",
        "rarity": 2,
        "resource": "res://resources/items/iron_dagger.tres",
        "used": false
      },
      null,
      null,
      {
        "changed_this_frame": false,
        "description_override": "",
        "is_phantom": false,
        "max_rarity": 8,
        "name_override": "",
        "rarity": 0,
        "resource": "res://resources/items/hunger_blade.tres",
        "used": false
      },
      {
        "changed_this_frame": false,
        "description_override": "",
        "is_phantom": false,
        "max_rarity": 8,
        "name_override": "",
        "rarity": 2,
        "resource": "res://resources/items/leather_pants.tres",
        "used": false
      },
      {
        "changed_this_frame": false,
        "description_override": "",
        "is_phantom": false,
        "max_rarity": 8,
        "name_override": "",
        "rarity": 1,
        "resource": "res://resources/items/leather_pants.tres",
        "used": false
      },
      {
        "changed_this_frame": false,
        "description_override": "",
        "is_phantom": false,
        "max_rarity": 8,
        "name_override": "",
        "rarity": 0,
        "resource": "res://resources/items/leather_pants.tres",
        "used": false
      },
      {
        "changed_this_frame": false,
        "description_override": "",
        "is_phantom": false,
        "max_rarity": 8,
        "name_override": "",
        "rarity": 0,
        "resource": "res://resources/items/natures_collar.tres",
        "used": false
      },
      {
        "changed_this_frame": false,
        "description_override": "",
        "is_phantom": false,
        "max_rarity": 8,
        "name_override": "",
        "rarity": 4,
        "resource": "res://resources/items/natures_collar.tres",
        "used": false
      },
      {
        "changed_this_frame": false,
        "description_override": "",
        "is_phantom": false,
        "max_rarity": 8,
        "name_override": "",
        "rarity": 1,
        "resource": "res://resources/items/silver_sabatons.tres",
        "used": false
      },
      {
        "changed_this_frame": false,
        "description_override": "",
        "is_phantom": false,
        "max_rarity": 8,
        "name_override": "",
        "rarity": 3,
        "resource": "res://resources/items/leather_chestplate.tres",
        "used": false
      },
      null,
      null,
      null
    ],
    "mode": 0,
    "modification_order": [
      15,
      0,
      10,
      1,
      6,
      11,
      5,
      12,
      16,
      2,
      9,
      3,
      4,
      14,
      17,
      8,
      7,
      19,
      13,
      18
    ],
    "resource": "res://resources/item_containers/inventory.tres",
    "sockets": []
  },
  "is_phantom": true,
  "keystones": [
    "res://resources/keystones/swarm.tres"
  ],
  "passive": "",
  "permanent_item_sets": [
    "res://resources/item_sets/vampiric.tres"
  ],
  "stat_modifiers": [
    {
      "amount": 25,
      "is_modifier": false,
      "resource": "res://resources/stats/cinder_damage.tres"
    },
    {
      "amount": 60,
      "is_modifier": false,
      "resource": "res://resources/stats/max_health.tres"
    }
  ]
}

Hello @axilirate,

It would be best if you execute register_storage_index in your script global scope inside a run_once function, otherwise the initial loading of existing storage objects that need to be indexed won’t happen, and only objects written after index registration will update the index.

Hope this helps.