So I have been working around GUIs for some time, and I noticed that ScreenGuis (and SurfaceGuis) have a ResetOnSpawn property. I know what it does.
When I work with GUIs, I always first reference all the PlayerGui contents and then work with the references. It's much quicker and cleaner than having to use playerGui:WaitForChild("ResultsGui")
or something like that at the start of every function, so I always set the ResetOnSpawn property to false.
However, I noticed that the property is set to true by default. I'm asking what the reasoning behind this is; why is it set to true by default if it makes it less convenient? Is there some performance-related reasoning as to why this is? What am I missing? Have I been scripting GUIs wrong all this time?
Alright, so I'm going to be giving you what I know about ResetOnSpawn.
First off, as we all know, LocalScripts
only run once, when ResetOnSpawn
is set to true, that means that you will get a new GUI with the same contents inside. This also means that any scripts inside of the GUI will run again when you respawn.
Sometimes, you may notice when working with custom health bars if you set ResetOnSpawn to false, the second time you spawn it won't work.
This is because when your character is deleted the humanoid is to so you would have to re connect the listener / event.
Mean while if ResetOnSpawn is true, it will automatically re run the code upon spawn and connect and update the variables.
There's many ways to script something and depending on your game you may need the property or not.
In the end it's up to how you want the game to function and whatever is more convenient / easier for you.
Hope this helped!