Making units with stats and skills

This module script has the stats of all units in the game:

return {
	{
		Name = "Drago",
		ID = 1,

		HP = 625,
		ATK = 100,
		DEF = 25,
	},
	
	{
		Name = "Senna",
		ID = 2,

		HP = 450,
		ATK = 175,
		DEF = 50,
	},
}

Now, every time I wanna deal damage or assign health value to a unit, all I have to do is retrieve this module and use the unit ID to get it’s values then use them accordingly.


Now, Let’s say I wanna add a skill to the unit named Drago, this skill would increase Drago’s next attack damage to be 300% of his base damage, so it would be 100 x 3 = 300 damage,

Drago would also play an animation and effects before dealing that damage.

Where and how would I store the data of each skill and the function that would play the skill animation and effects in a way that is extensible and easy to modify in the future?

Something I’ve recently started using a lot, is Instance Attributes. They are really powerful and incredibly useful for stuff like this. I used to have everything in a “master” module script, but I’ve found that it in some cases is easier to have a script be cloned onto the relevant instances than to push them into a modulescript.

At the end of the day, it is your choice how you do this.

No matter that, you might want to do it like this:
You probably want to store the different skills as (possibly) a list of names in the attributes of the character, and then have a modulescript for each skill in replicated storage, which will then handle the display of each skill. This means that all skills are entirely separate, which leads to faster development with less risk of new changes breaking old things.

1 Like