Hello, so I’m fairly new to DataStore2 I guess you could say and took me a bit to find out to actually save data and also load it but the problem I’m facing now is that Im trying to have it so when I have the same item in my inventory already it adds onto the value, but I only add the item’s name to the table were im saving that Data and I dont know how to retrieve the value exactly and make it update to the next number up, say I have one key it checks if I already have a key then updates the key too two keys etc.
I had an issue with this in the start, but here’s an example of my solution;
--loading
local Stuff = {
Money = 0,
XP = 0,
Activity = 0,
Kills = 0,
CurrentWeapon = "None",
WeaponsOwned = {"Default" , },
}
local X = PlayerDataStore:Get(Stuff)
Money.Value = X.Pounds
XP.Value = X.XP
Activity.Value = X.Activity
Kills.Value = X.Kills
CurrentWeapon.Value = X.CurrentWeapon
for i,v in pairs(X.WeaponsOwned) do
local Weapon = Instance.new("BoolValue" , WeaponsOwned)
Weapon.Name = v
end
--saving
local Data = { }
local WeaponsOwned = { }
local PlayerDataStore = DataStore2(DataStringStore,player)
for i,v in pairs(player.Profile:GetChildren()) do
if v.ClassName ~= "Folder" then
Data[v.Name] = v.Value
elseif v.ClassName == "Folder" and v.Name == "WeaponsOwned" then
for index,x in pairs(v:GetChildren()) do
table.insert(WeaponsOwned , x.Name)
end
end
end
Data["WeaponsOwned"] = WeaponsOwned
PlayerDataStore:Set(Data)
PlayerDataStore:Save()
It’s quite simple, you’re basically manually saving their data and manually loading it in tables.