Any ideas on how I should handle UI scripting?

Hello everyone. I have been working on a game for several months now and recently I have decided that I will be recoding a lot of things. The biggest thing I want to redo is how I handle UIs. Right now it is currently just local scripts in certain frames. I have found this highly inconvenient because

  • The code is inefficient
  • The code is not reusable
  • The code is very unorganized and all over the place, which opens the way for many small bugs

My solution to this was to convert to using modules as this seems like the best solution to keep code much more organized and most importantly reusable. What I cannot think of is how I should set up this system?

For example, some handle all of the player’s gui with module scripts inside the PlayerScripts folder, or some put modules inside each frame that needs scripting and then those modules are connected together with a core module. Basically there is a lot of ways to go about this and I am curious how others handle ui in their game. Any feedback is welcome!

Split into modules, make use of OOP. Have 1 core script that handles everything and makes use of the modules.

Personally I like to handle GUI with a single LocalScript named GuiManager. You can put some bindable events into it so other scripts can give it instructions.

I dont think you’ll need OOP unless there’s really a lot of stuff to do like a large inventory system. For example if you’re just making a shooting game, these games usually have very little GUI.

Yes but if you looked at OP’s points:

  • The code is inefficient
  • The code is not reusable
  • The code is very unorganized and all over the place, which opens the way for many small bugs

I do agree with you, since OP can make functions. If he plans on to make a trading system and more GUI stuff, OOP is definitely needed.

Do you have an example of how this would look?