# Restart Code

**URL:** <https://phaser.discourse.group/t/restart-code/12755>\
**Category:** Phaser 3\
**Created:** [January 10, 2023, 1:54am UTC](https://phaser.discourse.group/t/restart-code/12755 "2023-01-10T01:54:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![BusterSR](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/bustersr/32/7251_2.png) [@BusterSR](https://phaser.discourse.group/u/BusterSR)\
**Post date:** [January 10, 2023, 1:54am UTC](https://phaser.discourse.group/t/restart-code/12755/1 "2023-01-10T01:54:56Z")

</div>

Is there a way I can restart my game without resetting all the variables?

---

<div class="post-metadata">

**Author:** ![nish\_mishra](https://avatars.discourse-cdn.com/v4/letter/n/ee59a6/32.png) [@nish\_mishra](https://phaser.discourse.group/u/nish_mishra)\
**Post date:** [January 10, 2023, 6:14am UTC](https://phaser.discourse.group/t/restart-code/12755/2 "2023-01-10T06:14:13Z")

</div>

Store the variables you don’t want to reset in game object.  
for example: let game = new Phaser.Game({  
type: Phaser.WEBGL,  
backgroundColor: 0xffffff,  
transparent: true,  
});  
game.musicVolume = 1;

this.scene.restart(); would restart the scene.

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [January 10, 2023, 2:28pm UTC](https://phaser.discourse.group/t/restart-code/12755/3 "2023-01-10T14:28:32Z")

</div>

It really depends, I think we have to see your code.

---

<div class="post-metadata">

**Author:** ![BusterSR](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/bustersr/32/7251_2.png) [@BusterSR](https://phaser.discourse.group/u/BusterSR)\
**Post date:** [January 10, 2023, 5:30pm UTC](https://phaser.discourse.group/t/restart-code/12755/4 "2023-01-10T17:30:02Z")

</div>

> **[GitHub - BusterSR/Monster-Wars: A game about fighting monsters (work in...](https://github.com/BusterSR/Monster-Wars)**
>
> A game about fighting monsters (work in progress). Contribute to BusterSR/Monster-Wars development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [January 10, 2023, 7:29pm UTC](https://phaser.discourse.group/t/restart-code/12755/5 "2023-01-10T19:29:11Z")

</div>

> <https://github.com/BusterSR/Monster-Wars/blob/4506533a158f322a2273bce38566a4fbca0e2be5/index.html#L86-L87>

You can fix this by adding `this` as the third argument to `on(…)`, previous.

---

<div class="post-metadata">

**Author:** ![BusterSR](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/bustersr/32/7251_2.png) [@BusterSR](https://phaser.discourse.group/u/BusterSR)\
**Post date:** [January 10, 2023, 9:35pm UTC](https://phaser.discourse.group/t/restart-code/12755/6 "2023-01-10T21:35:29Z")

</div>

It’s working now thanks so much! 😃 do you have a github account I can credit in the repository description?

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [January 10, 2023, 10:45pm UTC](https://phaser.discourse.group/t/restart-code/12755/7 "2023-01-10T22:45:12Z")

</div>

> **[samme - Overview](https://github.com/samme)**
>
> samme has 111 repositories available. Follow their code on GitHub.
