Ability system using module scripts?

I’m currently designing an ability system which features many abilities packed into 1 magic type, and there are more than a few of these magic types.

With my current system, I’d have presumably one server script handling each magic type and all their abilities, or one giant server script which handles all of them

I’ve heard of a way to integrate module scripts to make cleaner and more efficient systems for handling so many abilities, can anyone point me in the right direction to learn about such systems?

Thank you! :grin:

ModuleScript is basically just a container that can return one type of data. You can use it to store functions, tables, strings, and anything else you can think of that can be stored in a normal script.

A more Roblox oriented approach: ModuleScript | Documentation - Roblox Creator Hub
A less Roblox oriented approach but still Lua: lua-users wiki: Modules Tutorial

1 Like

Wouldn’t I have to pack a lot of functions for abilities into this 1 module script tho? Wouldn’t that effectively achieve nothing?

It depends how you use the ModuleScripts. I personally would set up a tree like this:

image

Where I have a main module script that grabs sub-modules which grab even more sub-modules so everything essentially becomes a “drag and drop” functionality when I want to add new abilities or magic classes.

The Magic module would require it’s children and set them up in an easily indexable dictionary. Then the sub-modules when required will require their own children and do the same thing to setup the “magic abilities” for each magic in their own dictionary. The very bottom moduels (such as Typhoon Wall) will return a function that when called will preform the attack a player requested to do.

So if a player is a wizard type “Water” and requests to do a “Typhoon Wall” attack I would simply just do

local Magic = require(MagicModuleHere)

Magic["Water"]["Typhoon Wall"](Player)

Here is a Demo placefile you can check out:

ModuleDemo.rbxl (18.6 KB)

9 Likes

Thank you, exactly the kind of explanation I needed! Drag-and-drop seems extremely convenient

2 Likes