Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is the point of ResetOnSpawn?

Asked by 4 years ago

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?

1 answer

Log in to vote
0
Answered by 4 years ago

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!

0
Hmm I see. I still don't see the point of it being set to true by default - I bet much more GUIs actually do not need to reset on spawn... RiskoZoSlovenska 378 — 4y
0
It's true by default because of what BlackOrange said about updating variables. Quite a few scripts will need to update their variables and listeners when the player respawns. Such as the health bar he mentioned. But also since it generally won't hurt most other scripts. So it's overall less work for developers so they don't have to turn it on for every script that it's necessary. XxTrueDemonxX 362 — 4y
0
@RiskoZoSlovenska the reason it's on by default is probably because if isn't, most local scripts will break for new beginners (since they do not know to update their variables upon respawn) and will make starting things harder by giving them errors. Then again, it has to be set to some value to start so Roblox may have just randomly chose one or one that is more convenient for the users. BlackOrange3343 2676 — 4y
Ad

Answer this question