Getting no results from leaderboard_records_list function in RPC (Lua)

Hi,
I am trying to write a custom RPC to get the leaderboard data, but I have encountered a weird behaviour. This is the code I have wrote to debug the leaderboard records to see if there are any records available:

local nk = require("nakama")

local function debug_leaderboard(context, payload)
    local leaderboard_id = "doubleconnect_timetrial_leaderboard"
    local limit = 50
    local records = nk.leaderboard_records_list(leaderboard_id, nil, limit, nil, nil, nil)
    if not records or not records.records then
        return nk.json_encode({ status = "error", message = "No records found." })
    end
    return nk.json_encode({ status = "success", records = records.records })
end
nk.register_rpc(debug_leaderboard, "debug_leaderboard")

This code returns nothing. I don’t want any filter for the owners. first i tried {} but I read from here that it should be nil but it didn’t matter as I still don’t get any results.
I double-checked the ID for the leaderboards, and the records are available in the Console. Even when I use the ListLeaderboardRecords API, I get the records. But somehow from the code above, no results are generated. What am I doing wrong here?

Hello @alihanifi,

Are you running the latest version of Nakama (v3.25.0) ?

Best.

Thanks for responding.
Yes, I am using the latest version. In Configuration page says : Server version: 3.25.0+592b52c6

I think your code is incorrect, it should be:

local function debug_leaderboard(context, payload)
  local leaderboard_id = "doubleconnect_timetrial_leaderboard"
  local limit = 50
  local records = nk.leaderboard_records_list(leaderboard_id, nil, limit, nil, nil, nil)
  if (not records) then
    return nk.json_encode({ status = "error", message = "No records found." })
  end
  return nk.json_encode({ status = "success", records = records })
end
nk.register_rpc(debug_leaderboard, "debug_leaderboard")