Best way to handle multiple tools

Hey, I’ve wondered about the best way to handle multiple tools, possibly hundreds of different tools. Do I use various scripts for each tool and store them in that tool, or is there a way to handle multiple tools with fewer scripts? Does the amount of scripts affect the game?
I haven’t found any topics covering my question, and I would appreciate answers. Thanks.

To clarify my questions:
-Generally, does the number of scripts affect the game negatively (performance-wise) in any way (Not the code inside the scripts, I mean the scripts only)?
-What’s the best way to organize scripts for many different tools?

2 Likes

I strongly recommend using ModuleScripts for that as you can handle everything related to the local part that isn’t input in there, all in one modulescript (it may require a lot of parameters though), but to prevent the parameter issue you could set Attributes in every tool containing stats.
About input, you could use for index loops to loop through all swords and check whenever they’re used and then use module functions. Again, use attributes for very specific values. (i.e. cooldown time)

1 Like

I may be incorrect but having even 100 of scripts in your game wouldn’t affect its performance at all, even if it does its pretty much not noticeable unless the general code is poorly created (using old or deprecated methods, …) so it mostly depends on methods that are used in the script, but having a separate script for each tool also is not the best approach.

ModuleScripts are pretty much considered a container for Lua code, you may use the same code for multiple weapons but each with different specifications.

1 Like

Alright thanks for the reply. I’ll look into it

Thanks for the info man. Should I use multiple module scripts for different tools or just one for all?

One for all of course, for example 2 different weapons act pretty much the same, they both have reloading, shooting, aiming, ect but each come with different animations or effects.

You can use different ModuleScripts for different weapon types, because a weapon that shoots bullets is different from a melee weapon.

Thanks again mate. So I store variables and functions (with different parameters) in the module script (One module for each weapon type)
Then call the functions on the same script

That would work as well, but I also suggest you to learn about OOP (Object Oriented Programming) which is just great help for these sorts of things.

1 Like