Where should I store data?

I need to keep the characteristics of the monster, such as: how often it revives, how often it hits, at what distance it notices you, etc. Question, where can I store this data?

I found three options: ModuleScript, ServerStorage, Replicated Storage

But I don’t know which one is the best and most convenient + optimized.

Can you answer the question please? I will be glad if you can suggest more options where to store data, and also explain how to save everything there, if it is a module script then explain a little how it works, thanks.

1 Like

You should consider using attributes. Very easy to use and understand.

Instance:GetAttribute(attributename); -- gets the value of the attribute from an instance
Instance:SetAttribute(attributename, value); -- set an attribute with the specified value on an instance

You can also set attributes directly in the properties menu, you find them at the bottom. You could assign, for example, a damage attribute on Studio, then in the script where you manage the monster’s damage, you can just call :GetAttribute() on the monster and it’ll give you the value you set beforehand.

1 Like

Ok, but I need to create the attribute where, in the script? Or where?

In the property tab of Studio, at the bottom, you can find the “Attributes” section. Just add them onto your monster and use :GetAttribute to retrieve them whenever you need them

Okay, but if I want, for example, the same characteristics of several monsters. I don’t really want to create an attribute for each of them.

Oh well, in that case, I definitely recommend using a module script.
Let’s say this is your module:

return {
   ["Monster1"] = {
      Health = 500,
      Damage = 10,
      -- etc...
   },
   ["Monster2"] = {
      Health = 200,
      Damage = 6,
      -- etc...
   }
};

It’s a simple module that just returns a dictionary containing the monsters’ names and another dictionary that contains all their stats. To retrieve this dictionary:

local MonsterStats = require(PathToTheModule);
print(MonsterStats["Monster1"].Health); -- this would print 500
1 Like

Where should I store modular scripts, in serverScriptService?

In this case, since it doesn’t really store any function but rather just information, i’d keep it in ServerStorage

1 Like

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