Error creating match main.lua

When i trying to create Authoritative match i get error.

nakama_server-nakama-1 | {“level”:“error”,“ts”:“2024-03-31T21:09:56.468Z”,“caller”:“server/matchmaker.go:388”,“msg”:“Error running Matchmaker Matched hook.”,“error”:“Error running runtime Matchmaker Matched hook: /nakama/data/modules/modules/main.lua:20: error creating match: not found\nstack traceback:\n\t[G]: in function ‘match_create’\n\t/nakama/data/modules/modules/main.lua:20: in main chunk\n\t[G]: ?”}

In this code:

local nk = require(“nakama”)


local is_code_working = “&&&”

local function makematch(context, matched_users)
– print matched users
for _, user in ipairs(matched_users) do
local presence = user.presence
nk.logger_info(string.format(“Matched user ‘%s’ named ‘%s’”,presence.user_id, presence.username))
for k, v in pairs( do
nk.logger_info((“Matched on ‘%s’ value ‘%s’”):format(k, v))
is_code_working = “code_started”
local modulename = “lobby”
local setupstate = { invited = matched_users }
is_code_working = setupstate
local matchid = nk.match_create(modulename, setupstate)
return matchid


local function healthcheck_rpc(context, payload)
return nk.json_encode({[“succes”] = is_code_working })

nk.register_rpc(healthcheck_rpc, “healthcheck_rpc”)

Is a lobby .lua module with the match handler lifecycle functions present in the module folder? E.g.: nakama/data/modules/match.lua at master · heroiclabs/nakama · GitHub


If you’ve defined the functions within a module, you need to require it before you can reference functions from it.

How to do this?

In your main.lua file you need to add:

local lobby = require('lobby')

Thank you, this helped. Now i didnt get errors from main.lua
But i didnt see that nakama created authorative match

but server send info every tick

Oh, there is interesting moment - match created, but only for 1-2 secs. In nakama console i see that authorative matches = 1 but after 2 secs its been 0.

Oh, i finded. Sorry. Match returned nil.

Double check the server logs for errors. Otherwise, if the authoritative match is created but any of the match handler functions returns a null state, the match will be terminated.

Please have a look at our Lua code samples.

1 Like

Thank you for your help. I couldn’t do it all without you. The documentation is not completely complete. If it’s not difficult, could you answer a couple of questions?

  1. As I understand it, nakama opensource allows you to create a huge number of authorative matches and replicates the server logic code? And will it work if, for example, I deploy nakama on digital ocean?
  2. Can I connect to a separate postgresql database through nakama and take cards data from there, for example (about 100 cards), or should I immediately create a separate lua script with only cards data?
    Thank you very much in advance.
  1. Yes you can host Nakama open-source wherever you’d like. How many concurrent matches you’ll be able to achieve depend on your game logic and hardware the server is running on. Be aware that a production level deployment ready for scale is non-trivial, and that we cannot give support or help for such deployments outside of Heroic Cloud as there’s too many variables involved.

  2. Nakama can connect to any postgres database provided it’s accessible from the network and that it has the correct DSN, credentials and permissions. Nakama will need to create the database and schema it expects, I suggest you start with a clean database and use Lua scripts to populate it with data through the Storage Engine, I’d discourage you from using a pre-existing database, if that’s what you meant.

1 Like