Obviously everybody has their own way on setting up data for their players. I’d like to get some feed back on my proposed idea and whether this is efficient or not.
So the leaderstats would stay the same just like any other.
As for the shack, (where players will be making purchases at,) I got a little creative:
ItemsOwned folder would contain a bunch of bool values within their own designated folders, signifying whether the player has owned a specific item or not. For example, a bool value in the Aura folder is called “Fire,” and the value is true; meaning that the player owns that item.
For ItemsEquipped folder, I added StringValues because I figured it would make sense if I would be able to look that value up in a dictionary table containing all the items once I get around to the scripting.
I can’t tell whether I complicated things more or not, so you tell me. How do programmers/developers typically approach this?
Performance wise, I don’t see a problem with this method of saving.
However I don’t see why it is necessary to have a value for every item you have owned / equipped. If you start introducing lots of items you will quickly end up having tonnes of values that will start to get quite messy quickly.
I would suggest it is easier and cleaner to cache the players data in a table for a couple of reasons, it helps keep your explorer clean and is easier to add items later without having to remember to add its value and it is easier to quickly loop through that table to add it to a datastore. If you are unsure on how to do this, you could use either Quenty’s datastore system or Datastore 2. The only exception in this method is the leaderstats which will only show if you have that folder and values but you can easily update those values when you change the Coins / Gems value.
If you do really want to use the values + folders approach I would recommend that you create the values in a script when a player buys an item and deletes said value again when they loose it, this would make it easier for you to add new content without having to add more values and keep your explorer clean.
Have one master dictionary with the names of everyone in the server as the key (removing after the player has left and saved their data). Then the key is simply all of their data, however if you are going to use Data Store 2 this is unnecessary because it automatically caches the data for you.
If you do end up using DS2, what I find works really well is create a module script where you have 2-3 functions per data value depending on the data type.
Set
Increment
Get / GetTable
Then all you need to do is require the module and call the appropriate function.
This is what I do in my game:
-- Gold
function Data:GetGold()
local Save = Data.PlayerSaveLoaded[self.Name] -- Save slot
local GoldDataStore = DataStore2("Gold"..Save, self)
return GoldDataStore:Get(DefaultValues.Gold)
end
function Data:IncrementGold(Amount)
local Save = Data.PlayerSaveLoaded[self.Name]
local GoldDataStore = DataStore2("Gold"..Save, self)
GoldDataStore:Increment(Amount, DefaultValues.Gold)
game.Players[self.Name].leaderstats.Gold.Value = Data.GetGold(self) -- Update leaderstats
Remotes.UpdateGui:FireClient(self, "Gold", Data.GetGold(self)) -- Update the player UI
end
function Data:SetGold(Amount)
local Save = Data.PlayerSaveLoaded[self.Name]
local GoldDataStore = DataStore2("Gold"..Save, self)
GoldDataStore:Set(Amount)
game.Players[self.Name].leaderstats.Gold.Value = Data.GetGold(self) -- Update leaderstats
Remotes.UpdateGui:FireClient(self, "Gold", Data.GetGold(self)) -- Update the player UI
end