# Why doesn't my Set Player State work?

**URL:** https://forum.makecode.com/t/why-doesnt-my-set-player-state-work/27988
**Category:** Help
**Tags:** extension, game
**Created:** [March 28, 2024, 4:40pm UTC](https://forum.makecode.com/t/why-doesnt-my-set-player-state-work/27988 "2024-03-28T16:40:17Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Kee](https://avatars.discourse-cdn.com/v4/letter/k/e9bcb4/32.png) [@Kee](https://forum.makecode.com/u/Kee)
#### Post date: [March 28, 2024, 4:40pm UTC](https://forum.makecode.com/t/why-doesnt-my-set-player-state-work/27988/1 "2024-03-28T16:40:17Z")

</div>

In the info blocks of the multiplayer extension. I made a new player state called “Direction”. I try setting the Direction in the on start/on player connected blocks as well as setting it to a different number every time a directional key button is pressed. But the Player State still reads as “0”. By the way if anyone is curious; 1 means up, 2 means right, 3 means down, and 4 means left. Is this a bug with Makecode Arcade itself or am I doing this wrong since I’ve tried everything, and it doesn’t change the number. Here’s the link to my game to see my code: [https://arcade.makecode.com/S29349-30338-59749-30192](https://arcade.makecode.com/S29349-30338-59749-30192)

---

<div class="post-metadata">

### Author: ![eanders](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/eanders/32/3134_2.png) [@eanders](https://forum.makecode.com/u/eanders)
#### Post date: [March 28, 2024, 5:19pm UTC](https://forum.makecode.com/t/why-doesnt-my-set-player-state-work/27988/2 "2024-03-28T17:19:22Z")

</div>

Thank you for taking time to post your issue here. This is a known bug (see: [https://github.com/microsoft/pxt-arcade/issues/5952](https://github.com/microsoft/pxt-arcade/issues/5952)). In the meantime, here’s a workaround:

Add this block to the top of your “on player connected” handler:  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/9/9fec794bae4f2f7ea55d9764816d4885baa4ecad.png)

The problem is that MakeCode isn’t creating quite enough storage space on the player to hold the highest-numbered custom state slot defined by the program (which happens to be “Direction” in this case). The workaround is to pre-allocate extra slots beyond the highest-numbered slot defined by the program, creating some headroom so the bug isn’t hit.

---

<div class="post-metadata">

### Author: ![Kee](https://avatars.discourse-cdn.com/v4/letter/k/e9bcb4/32.png) [@Kee](https://forum.makecode.com/u/Kee)
#### Post date: [March 28, 2024, 8:19pm UTC](https://forum.makecode.com/t/why-doesnt-my-set-player-state-work/27988/3 "2024-03-28T20:19:28Z")

</div>

Thank you! I thought I was just bad at coding lol. Coding makes you regret your whole life sometimes.

---

<div class="post-metadata">

### Author: ![eanders](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/eanders/32/3134_2.png) [@eanders](https://forum.makecode.com/u/eanders)
#### Post date: [March 28, 2024, 8:20pm UTC](https://forum.makecode.com/t/why-doesnt-my-set-player-state-work/27988/4 "2024-03-28T20:20:05Z")

</div>

I’m the one bad at coding. That was my bug 🙂
