Config or ModuleScripts?

Hello! I’m making a turn based RPG in Roblox, something akin to Persona. I need a way to store specific data as things like numbers. For example, an item would have a couple of values:

-The weight of the item (in a number value)
-The coin value of the item (preferably in an int value, although roblox may handle ints differently)
-The type of the item (a weapon, a quest item, etc)
-Another configuration or class instance that holds type specific values (for example if it’s a weapon, the configuration would have the weapons damage, damage type, etc.)
-The model connected to the item (for configurations, this would be an ObjectValue, and the type-specific values would be in the model)

Currently, it’s set up like a configuration. Here’s an example:

but if I was to implement it like a moduleScript, it’d be something like this:

local Example = {}
Example.__index = Example

function Example.New(integerValue:  number, stringValue: string)
	local newExample = {}
	newExample.integerValue = integerValue
        newExample.stringValue = stringValue
	setmetatable(newExample, Example)
	return newExample
end

function Example:printString()
	print(self.stringValue)
end

return Example

and thus after we’d have more stuff, potentially going with inheritance and such.

I went on the forum to ask if my configuration method was solid, or whether or not I’d need to change it to help for performance or any other issues. Currently it works fine, but I don’t want to run into any roadbloacks. Should I swap to modules and OOP completely or just stick with configurations, or just do a mix of the two? Currently I’m using configurations for items, skills (basically most things people can do in battle-attacks, heals, etc.), and thinking of using it for stats (think an attack stat, a defense stat, etc.)

1 Like

It depends what it is like if you do such as a shop system I would use a module script but for somthing like a swords damage for example I would put a number value under the sword called “Damage”

I use module scripts for everything, they are very useful and customizable. Stuff isn’t limited by a NumberValue, you can have everything organized under one module. Such as damage, range, headshot multiplier, sound effects, etc.

This also prevents from creating a bunch of instances that are not needed for all the weapon data for example.

An example:

--!strict
return {
	Damage = {
		['Head'] = 8,
		['Torso'] = 4,
		['LeftArm'] = 4,
		['RightArm'] = 4,
		['LeftLeg'] = 2,
		['RightLeg'] = 2,
	},
	
	Range = 50,
	
	Sounds = {
		Reload = 00000,
		Shoot = 00000,
		Inspect = 00000,
	},
	
	Animations = {
		Reload = 000000,
		Shoot = 000000,
		Inspect = 000000,
	},
}
1 Like

Should I then just use ModuleScripts for stuff that’s connected to models, and Configs for other stuff?

1 Like

Also I’m pretty sure that’s just a table, so you’ll need to make a new ModuleScript for every new gun you might make-shouldn’t you just make a constructor in the module?

1 Like