# Server deciding players' turn at the start of the match

**URL:** <https://forum.heroiclabs.com/t/server-deciding-players-turn-at-the-start-of-the-match/1631>\
**Category:** Game Design\
**Created:** [May 11, 2021, 7:53am UTC](https://forum.heroiclabs.com/t/server-deciding-players-turn-at-the-start-of-the-match/1631 "2021-05-11T07:53:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdee5](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@mdee5](https://forum.heroiclabs.com/u/mdee5)\
**Post date:** [May 11, 2021, 7:53am UTC](https://forum.heroiclabs.com/t/server-deciding-players-turn-at-the-start-of-the-match/1631/1 "2021-05-11T07:53:54Z")

</div>

For a game like tic tac toe , when two players are connected, how to randomly assign each player either “X” or “O” from server side (preferably in lua). The game is made with godot but I believe the server code will be same for any other game engine.

---

<div class="post-metadata">

**Author:** ![novabyte](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/novabyte/32/1324_2.png) [@novabyte](https://forum.heroiclabs.com/u/novabyte)\
**Post date:** [May 11, 2021, 9:38am UTC](https://forum.heroiclabs.com/t/server-deciding-players-turn-at-the-start-of-the-match/1631/2 "2021-05-11T09:38:41Z")

</div>

Hi @mdee5 👋

That’s a great question. We actually have a TicTacToe demo with a full server implementation that you can look at in Go, TypeScript, and/or Lua:

- [nakama-project-template/match\_handler.go at master · heroiclabs/nakama-project-template · GitHub](https://github.com/heroiclabs/nakama-project-template/blob/master/match_handler.go)
- [nakama-project-template/match\_handler.ts at master · heroiclabs/nakama-project-template · GitHub](https://github.com/heroiclabs/nakama-project-template/blob/master/match_handler.ts)
- [game-xoxo-nakama-server/tictactoe\_match.lua at main · defold/game-xoxo-nakama-server · GitHub](https://github.com/defold/game-xoxo-nakama-server/blob/main/tictactoe_match.lua)

In principle what you do is either make the match creator have the O or X; alternatively you sort the list of match presences alphanumerically so that all game clients within the match can deterministically know who goes first (and that player will be defined to use O or X).

Hope that helps.

---

<div class="post-metadata">

**Author:** ![mdee5](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@mdee5](https://forum.heroiclabs.com/u/mdee5)\
**Post date:** [May 11, 2021, 10:07am UTC](https://forum.heroiclabs.com/t/server-deciding-players-turn-at-the-start-of-the-match/1631/3 "2021-05-11T10:07:39Z")

</div>

Can we send message to single user only from the server side?  
` dispatcher.broadcast_message(*)`  
sends message to every joined users ( I guess).

---

<div class="post-metadata">

**Author:** ![novabyte](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/novabyte/32/1324_2.png) [@novabyte](https://forum.heroiclabs.com/u/novabyte)\
**Post date:** [May 11, 2021, 10:45am UTC](https://forum.heroiclabs.com/t/server-deciding-players-turn-at-the-start-of-the-match/1631/4 "2021-05-11T10:45:00Z")

</div>

@mdee5 Yes you can of course broadcast messages to a single user, group of users, or all users within the multiplayer match. You can see an example of that in the codebase links I shared here:

> <https://github.com/heroiclabs/nakama-project-template/blob/master/match_handler.ts#L269>
