Attributes or ModuleScript?

Hello,

So I was wondering whether to use Attributes Or a ModuleScript

So When Having Settings, Like Firerate, Damage, and AssetIds

Would I use Attributes, or a ModuleScript for these kinds of Settings?

Attributes are replicated when set on the server and so sometimes its possible to avoid needing a very annoying RemoteFunction system to get and set values like this. Attributes are also preferred when part of the information conveyed is its own position in the Explorer hierarchy. For example I use them in my current project to add extra info to Attachments about how they should behave when dragged and dropped and connected. If I did this separately in a table or module I would need an additional way of pointing each value to the Attachment it effects, and a way to sync that between client and server.

2 Likes

It depends on your specific needs and preferences. Here are some points to consider when deciding between using attributes or a module script for storing settings:

  • If you want to be able to access the settings from multiple places in your game, such as from different scripts or GUI elements, then a module script may be a good choice. This is because module scripts can be accessed from anywhere in your game, and you can use them to store and retrieve values for your settings.
  • If you want to be able to easily modify the settings from different places in your game, then attributes may be a good choice. This is because attributes can be easily set and accessed using simple dot notation (e.g. object.AttributeName = value).
  • If you only need to access the settings from a single script, or if you don’t need to modify the values of the settings, then you might consider using local variables within the script instead of using attributes or a module script.

Ultimately, the choice between using attributes or a module script will depend on your specific needs and preferences. It may also be possible to achieve your goals using a combination of both approaches.

1 Like

Attributes cannot be accessed using dot notation. In order to get the value of an attribute, you have to use:

local ammoAmount = gun:GetAttribute("Ammo")
2 Likes

Either works. For some reason, it has become a habit for me to use ModuleScripts instead of Attributes, though I think attributes are actually more logical… but I’m too lazy to change. lol

2 Likes

How about using Require function

using require is fine. either method is fine

Main use is just for Storing AnimationIds and other kinds of Data for the gun, Just wondering if it would be better for Attributes or a ModuleScripts in theis case.

I like module scripts better because they are easier to read, type in, and to edit.

There is no wrong option, but module scripts have more capabilities and I would almost never use attributes.

I like ModuleScripts more, there are a few reasons for this:

  1. ModuleScripts are designed specifically for storing and organizing data, whereas Attributes are designed for storing metadata about an object.
  2. ModuleScripts can be easily shared between different parts of your game, whereas Attributes are tied to a specific object and cannot be easily shared.
  3. ModuleScripts are easier to update and maintain, because you can change the values in the script and it will automatically update everywhere it is used in your game. With Attributes , you would need to manually update the values on each object that uses them.

That being said, it is possible to use Attributes for storing settings, especially if you only need to store a small amount of data. However, for larger or more complex sets of data, it is generally more convenient to use a ModuleScript .

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.