Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you clean your game up and organize it?

Okay, sorry the title is not very accurate but I couldn't else explain it. Anyway what I'm talking about is that how would I make my game very clean? least amount of scripts possible? For an example how would I create a custom dialog using stringvalues with the values to match the dialog's text? Another one would be a bunch a treasure chests in the workspace I shouldn't have to put individual scripts in each one of them. One giant script should control everything. But how should I do this?

All the beginning I've developed on ROBLOX I've tryed to organize my game as much as possible by using less scripts and cleaner ways.

1 comment

0

One thing to note is that you don't always have to reference something with script.Parent. If you can get the path to it, you can access it. For example: workspace.Model1.Folder.Part. You can also loop through the children of an instance and do something to every one.

2 answers

✓ Accepted answer

Clean and organized working environments!

This is a great question to ask, especially considering a majority of people who experience issues with their game have a very messy working environment, and don't bother asking how to fix it. Here are a few ways you can keep your game (and code) organized, and clean...

Names

A lot of people find giving specific names to certain objects, tasks, variables, etc, very annoying and tedious, and therefore opt for something shorter quicker. This however, is something you should give a considerable amount of thought to when necessary. Not only will good descriptive names help you remember where or what something is, or how it functions, but it keeps your code (or working environment) a lot more human readable (and subsequently, easier to navigate and debug!). Would you rather your dragon model be named something like aabbcc, or TheMightyDragon?

Location

You should have a place for everything, and everything should be in it's place. Have a lot of remotes in your game? Create a folder and name it Remotes. Have a ton of module scripts that both the client and server should have access to? Create a modules folder and throw it in ReplicatedStorage. Everything should be a hierarchical system that contains something relevant to it's category. If you have a bunch of treasure chests in your game, create a folder for treasure chests and throw them all in there. Both you, and your script will find it a lot easier to look through.

Use the right service

This kind of fits with location, but using the correct service isn't just for making your working environment cleaner, it's also highly practical. For example, if you have a set of objects that you don't want replicating to the client right away, you can store them in ServerStorage, where all contents are stored completely server-sided until parented somewhere else by the server. If you do want them to replicate, throw them in ReplicatedStorage. Don't go and use something random like Lighting to hold everything. If you want to create an introduction system, try using ReplicatedFirst with a local script instead of cloning something to a PlayerGui when the player joins, etc etc etc... Point is, storage services exist for a purpose, and you should know what their purpose is!

Don't duplicate scripts

Before you just read this title and decide to only use one script for everything, hold on. Having multiple scripts for handling different tasks is not a bad thing. I'd in fact, encourage it. However, if your game is creating a hundred different scripts for a hundred different parts, perhaps then you should consider a better method. Most of the time, I'd suggest keeping it at one script to manage everything, and having a bunch of modules that script can require to organize each task it carries out. If you feel like it's necessary to have more than one script manage one end of your system, go ahead! It is not deemed inefficient, and you shouldn't be hesitant to split up your code into subsections for different tasks. Just make sure it's absolutely necessary.


Anyway, that's my opinion on keeping your code and working environment clean and organized. Others may have different opinions, and that's fine too. As long as what you deem "organized" isn't beyond practical, and it helps you understand something better, you should implement it. If you have any questions, just let me know.

  1. Always use one large script rather than a lot of tiny scripts in instances or whatever. However it's important to cap your script size to keep them readable.
  2. For sort of one-off random things such as music or admin or gamepasses do not be afraid to make a separate script.
  3. Most importantly, anytime a script has thousands of lines just to define functions (usually the main script) then you need to use a module script. There is literally no reason not to do this; You never have to repeat yourself, everything has one clear source, your scripts are much more readable, you are not restricted to one script which has the main functions, and it works locally too.
  4. Organization: it is simple. Use the workspace only for active parts. Put all events and values in ReplicatedStorage. Everything else goes in ServerStorage. Grouping: if dealing with parts, use a model. Otherwise use a folder.
  5. Script content: use sane, consistent conventions. Put configuration variables at the top, then WaitForChild things, then define functions, then loop. The bare minimum for comments is to put a comment before every code block, plus a comment for anything that is not totally clear such as math.

Do all of this and anyone who looks at your game will love you.

This discussion is preserved as it was. New answers, comments, and votes are closed.