Question on creating/organizing systems efficiently

so i’m in the middle of making an explosive system. its my first time making an explosive system so i’m still trying to understand how to structure systems.

i made a class called “Explosive” which creates an explosive model and has a launch function for throwing the explosive.

i have an “ExplosiveController” which is a controller that handles everything to do with the VFX, sound effects, the explosive class, etc. (not sure if this is the correct way to use controllers but anyways.)

my question is how should i properly structure an explosive system or systems in general? there’s multiple things to account for such as projectile motion & trajectory, VFX, network handling, etc. just trying to get some feedback before my code turns spaghetti. :moai:

i appreciate any advice thx u so much!!! :slight_smile:

The approach you may consider for this situation, is having a “main class module” for the explosives in general, and from that same module, stem other modules with names that describe what they contain (on a side note, since they’re parented to the “Explosive” class, it’s self-evident they are related to explosions, so you don’t need to make it redundant by having them named “Explosives [what it does]”).

To illustrate what I mean, instead of having something like the picture you posted (looks messy and unintuitive… your editing of the image was top-notch):


Where the main module, handles exclusively when and how stuff happens, and the children modules, contain the actual what happens, for example:

Explosive module dictates that the Effects module shall instantiate an explosion VFX/SFX at the passed CFrame, using the configuration values from the Config module.

In the sense that, once again, the main module says when/how, and the children modules define what actually happens when the main module wants anything (when they’re being called/invoked).

That format for modules has worked fine for me; Feel free to attempt at it and letting me know how that went.
Obviously, it’s fine if it just doesn’t fit your style, completely valid and even expected at some point… whatever floats your boat, there aren’t strict rules regarding organization, just standards and conventions that don’t inherently command any kind of authority by themselves (just their effects have gained them their respective reputation).

1 Like

if you require just the effects on the client, I recommend still having them in just one location, and if it happens to be in ServerStorage(or some other server only location), at the start you just need to do something along the lines of

for i, Class in Classes do
    local Effect = Class:FindFirstChild("Effects")
    if Effect then
        local EffectClone = Effect:Clone()
        EffectClone.Name = Class.Name.."Effects"
        EffectClone.Parent = ReplicatedStorage.Effects
    end
end

to shuffle over a copy to a replicated location at server startup so you only have to maintain one script

1 Like

many thanks for taking the time to respond and for giving me advice!

i only just noticed now, yeah that was super messy of me. i shouldve kept the names short.

that format is working for me as well. i usually do it this way. trying to organize systems can get complicated and i’ve often split even the smallest functions into child modules that are like 30 lines of code but the problem with that is that i end up requiring like 50 different modules later on in the parent class and it feels like i’m naming variables rather than programming… i’ll still try different styles as im still in the experimentation phase.

thanks a million for your help!! :slight_smile:

1 Like

i’ve noticed a lot of top developers doing this actually. i did something similar with my sound effects which replicates a sound effects library to ReplicatedStorage from a table of sound ID’s on server start up.

i will definitely take this into consideration as i completely forgot about that. thanks for your help mate!