<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alvaro Sebastian Zweig</title>
    <description>The latest articles on DEV Community by Alvaro Sebastian Zweig (@azweig).</description>
    <link>https://dev.to/azweig</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4114591%2F2cc1a713-6e63-4863-8554-3e4c601d28b5.png</url>
      <title>DEV Community: Alvaro Sebastian Zweig</title>
      <link>https://dev.to/azweig</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/azweig"/>
    <language>en</language>
    <item>
      <title>The respawn button that worked for the wrong reason</title>
      <dc:creator>Alvaro Sebastian Zweig</dc:creator>
      <pubDate>Mon, 07 Sep 2026 21:02:25 +0000</pubDate>
      <link>https://dev.to/azweig/the-respawn-button-that-worked-for-the-wrong-reason-32ge</link>
      <guid>https://dev.to/azweig/the-respawn-button-that-worked-for-the-wrong-reason-32ge</guid>
      <description>&lt;p&gt;I spent two days on a bug that was, the whole time, telling me it was fine.&lt;/p&gt;

&lt;p&gt;I'm building a Bomberman-style arena game. Hub with doors, you stand on one, it takes you to the arena, you drop bombs, you probably die. After you die there's a &lt;strong&gt;PLAY AGAIN&lt;/strong&gt; button.&lt;/p&gt;

&lt;p&gt;PLAY AGAIN did not work. Press it and you'd end up in the middle of the hub instead of back at your door. And the maddening part was that the &lt;em&gt;other&lt;/em&gt; path through the same code — the automatic "return to the hub when the round ends" — worked perfectly.&lt;/p&gt;

&lt;p&gt;Same function. Same argument. One worked, one didn't.&lt;/p&gt;

&lt;h2&gt;
  
  
  What was actually happening
&lt;/h2&gt;

&lt;p&gt;Lobby and arenas live in the same place, 320 studs apart, and I move players between them with &lt;code&gt;PivotTo&lt;/code&gt;. Here is the real sequence:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. you get killed        -&amp;gt; Humanoid.Health = 0
2. you press PLAY AGAIN  -&amp;gt; server PivotTo's you to your door
3. ~2s later Roblox REPLACES your character (Players.RespawnTime)
   and the new one spawns at the SpawnLocation
4. you end up in the middle of the hub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 2 was moving a corpse.&lt;/p&gt;

&lt;p&gt;The character I so carefully repositioned was already scheduled for deletion. Two seconds later Roblox threw it away and built a fresh one at the &lt;code&gt;SpawnLocation&lt;/code&gt;, and everything I'd done to the old one went with it. Not &lt;em&gt;some&lt;/em&gt; placements of dead players were lost — &lt;strong&gt;all of them were&lt;/strong&gt;, always, from the first day.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why it took two days
&lt;/h2&gt;

&lt;p&gt;Because the other path looked like it worked.&lt;/p&gt;

&lt;p&gt;When a round ends normally, the game also sends everyone back to the hub, through the exact same function. And it looked flawless. Every single time, players ended up in the hub.&lt;/p&gt;

&lt;p&gt;They ended up in the hub because &lt;strong&gt;the SpawnLocation is in the hub&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;My code was doing nothing. Roblox's default respawn was producing the correct result on its own, and I was taking the credit. The feature "worked" in the sense that the observable outcome matched what I wanted, and for the entirely wrong reason.&lt;/p&gt;

&lt;p&gt;That's a category of bug I now actively fear. A broken thing that looks broken is a morning's work. A broken thing that looks &lt;em&gt;fine&lt;/em&gt; costs you two days, and you only find it because some unrelated path — the one where the right answer and the accidental answer happen to differ — finally disagrees.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix
&lt;/h2&gt;

&lt;p&gt;Stop trying to place the player. Write down where they're supposed to end up.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lua"&gt;&lt;code&gt;&lt;span class="n"&gt;TeleportManager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pendiente&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;   &lt;span class="c1"&gt;-- [userId] = { destino, velocidad }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If they're alive, apply it now. If they're dead, apply it to the new character on &lt;code&gt;CharacterAdded&lt;/code&gt;. It doesn't matter what caused the respawn, who killed them, or how long Roblox takes to get around to it. The intent survives the character.&lt;/p&gt;

&lt;p&gt;The general shape, which I suspect is the real lesson: &lt;strong&gt;when the thing you're modifying has a shorter lifetime than the intent you're expressing, store the intent, not the modification.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Two things I'm still unsure about
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Is a pending-destination table the normal pattern here, or is everyone else setting &lt;code&gt;RespawnLocation&lt;/code&gt; and letting the engine put the player in the right spot to begin with? Mine feels like I'm working around the engine rather than with it.&lt;/li&gt;
&lt;li&gt;Is there a less indirect way to know a &lt;code&gt;Humanoid&lt;/code&gt; is about to be replaced than checking &lt;code&gt;Health&lt;/code&gt;? Branching on "is this dead" to answer "will this still exist in two seconds" is reading a symptom, not a cause. It works, but I don't love it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you've shipped something with a custom respawn flow, I'd like to hear which of those you landed on.&lt;/p&gt;




&lt;p&gt;The game, if you want to see what it's for: &lt;a href="https://www.roblox.com/games/79128877763618/" rel="noopener noreferrer"&gt;BOMB MAYHEM&lt;/a&gt;. It's free and it's on Roblox, so you'll need an account; it's currently rated 16+. Neither of those is needed to have an opinion about the code.&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>roblox</category>
      <category>lua</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
