# Error creating match main.lua

**URL:** <https://forum.heroiclabs.com/t/error-creating-match-main-lua/5108>\
**Category:** Runtime Framework\
**Tags:** matches, lua, server-framework\
**Created:** [March 31, 2024, 9:15pm UTC](https://forum.heroiclabs.com/t/error-creating-match-main-lua/5108 "2024-03-31T21:15:42Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![F1ow](https://avatars.discourse-cdn.com/v4/letter/f/b9bd4f/32.png) [@F1ow](https://forum.heroiclabs.com/u/F1ow)\
**Post date:** [March 31, 2024, 9:15pm UTC](https://forum.heroiclabs.com/t/error-creating-match-main-lua/5108/1 "2024-03-31T21:15:42Z")

</div>

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”)

nk.logger\_info(“lua\_loaded”)

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(user.properties) do  
nk.logger\_info((“Matched on ‘%s’ value ‘%s’”):format(k, v))  
end  
end  
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  
end

nk.register\_matchmaker\_matched(makematch)

local function healthcheck\_rpc(context, payload)  
nk.logger\_info(“healthcheck\_rpc”)  
return nk.json\_encode({[“succes”] = is\_code\_working })  
end

nk.register\_rpc(healthcheck\_rpc, “healthcheck\_rpc”)

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [April 1, 2024, 9:45am UTC](https://forum.heroiclabs.com/t/error-creating-match-main-lua/5108/2 "2024-04-01T09:45:38Z")

</div>

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](https://github.com/heroiclabs/nakama/blob/master/data/modules/match.lua)

---

<div class="post-metadata">

**Author:** ![F1ow](https://avatars.discourse-cdn.com/v4/letter/f/b9bd4f/32.png) [@F1ow](https://forum.heroiclabs.com/u/F1ow)\
**Post date:** [April 1, 2024, 9:50am UTC](https://forum.heroiclabs.com/t/error-creating-match-main-lua/5108/3 "2024-04-01T09:50:22Z")

</div>

> [@sesposito](#):
>
> e match handler lifecycle functions present in

yes

 ![image](https://us1.discourse-cdn.com/flex020/uploads/heroiclabs/original/2X/d/d5685ab734b9e71add2f319fdc2586b5ddbe9cc2.png)

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [April 1, 2024, 10:14am UTC](https://forum.heroiclabs.com/t/error-creating-match-main-lua/5108/4 "2024-04-01T10:14:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![F1ow](https://avatars.discourse-cdn.com/v4/letter/f/b9bd4f/32.png) [@F1ow](https://forum.heroiclabs.com/u/F1ow)\
**Post date:** [April 1, 2024, 10:20am UTC](https://forum.heroiclabs.com/t/error-creating-match-main-lua/5108/5 "2024-04-01T10:20:10Z")

</div>

How to do this?

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [April 1, 2024, 10:30am UTC](https://forum.heroiclabs.com/t/error-creating-match-main-lua/5108/6 "2024-04-01T10:30:48Z")

</div>

In your `main.lua` file you need to add:

```auto
local lobby = require('lobby')

```

---

<div class="post-metadata">

**Author:** ![F1ow](https://avatars.discourse-cdn.com/v4/letter/f/b9bd4f/32.png) [@F1ow](https://forum.heroiclabs.com/u/F1ow)\
**Post date:** [April 1, 2024, 11:19am UTC](https://forum.heroiclabs.com/t/error-creating-match-main-lua/5108/7 "2024-04-01T11:19:51Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex020/uploads/heroiclabs/original/2X/1/170507c33f5b936f6c2b50cca248c5ca97a0a61f.png)

 ![image](https://us1.discourse-cdn.com/flex020/uploads/heroiclabs/original/2X/0/0d92d5417274d2a253d4ba95a92188631a28907b.png)

but server send info every tick

 ![image](https://us1.discourse-cdn.com/flex020/uploads/heroiclabs/original/2X/6/6982d495bd8b1d0cb8352c67426f3f16054af583.png)

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.

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [April 1, 2024, 11:37am UTC](https://forum.heroiclabs.com/t/error-creating-match-main-lua/5108/8 "2024-04-01T11:37:37Z")

</div>

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](https://heroiclabs.com/docs/nakama/server-framework/lua-runtime/code-samples/#match-handler).

---

<div class="post-metadata">

**Author:** ![F1ow](https://avatars.discourse-cdn.com/v4/letter/f/b9bd4f/32.png) [@F1ow](https://forum.heroiclabs.com/u/F1ow)\
**Post date:** [April 1, 2024, 11:42am UTC](https://forum.heroiclabs.com/t/error-creating-match-main-lua/5108/9 "2024-04-01T11:42:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [April 1, 2024, 12:03pm UTC](https://forum.heroiclabs.com/t/error-creating-match-main-lua/5108/10 "2024-04-01T12:03:03Z")

</div>

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.
