And there are many ways to store your data, if you can have multiple of each weapon you better make it like this:
local Data = {
Weapons = {
{
1, -- Identifyer for e.g. "Knife"
10, -- Damage
5, -- Range
1, -- Delay
148, -- Uses left
},
};
}
Or if all weapons have set values and you don’t want to store stuff like “uses left”, you can store the Damage, Range and Delay in a separate table
local WeaponInfo = {
[1] = {
Name = "Knife";
Damage = 10;
Range = 5;
Delay = 2;
},
[2] = {
Name = "Sword";
Damage = 20;
Range = 10;
Delay = 4;
},
[6] = {
Name = "Grenade";
Damage = 200;
Range = 30;
Delay = 20;
},
[7] = {
Name = "Gun";
Damage = 5;
Range = 50;
Delay = 1.5;
},
}
local Data = {
Weapons = {
1, -- Identifyer for e.g. "Knife"
2, -- Identifyer for e.g. "Sword"
2, -- Identifyer for e.g. "Sword"
7, -- Identifyer for e.g. "Gun"
1, -- Identifyer for e.g. "Knife"
6, -- Identifyer for e.g. "Grenade"
2, -- Identifyer for e.g. "Sword"
1, -- Identifyer for e.g. "Knife"
1, -- Identifyer for e.g. "Knife"
};
}
Next to that there are different ways to store data too, like if you have consumable items you are able to collect a lot of, it’s better to store these as a dictionary in your data:
local FoodInfo = {
A = {
Name = "Apple";
HungerPoints = 5;
},
B = {
Name = "Banana";
HungerPoints = 10;
},
P = {
Name = "Pear";
HungerPoints = 8;
},
M = {
Name = "Melon";
HungerPoints = 25;
},
}
local Data = {
Food = {
A = 1235; -- 1235 Apples
B = 186; -- 186 Bananas
M = 24; -- 24 Melons
P = 72; -- 72 Pears
};
}
There are way more ways to store your data, but make sure it:
- Holds all data you need.
- Holds as least as possible duplicate data.
- Doesn’t take up unnecessary space
- Is future proof, in case you want to adjust things in the future.
Edit:
A great practise is deserialisation after the initial get request and serialisation before any save requests.