How to use DataStore2 - Data Store caching and data loss prevention

I am trying to figure out how to make a decent inventory system using Datastore2.
and i`m going back and forward trying to figure out what the best way is.

inventory background info and wishlist
  • 27 player inventory slots
  • bankslots start at 54 (2x27) → maybe upgradable later
  • max stack count difers between bank and inventory
  • ability to insert items → example (inventory:insert({“sword”,1,“shield”,1}))(and error if it fails)
  • ability to destroy items-> example (inventory:Destroy({“sword”,1,“shield”,1}))(and error if it fails)
  • ability to split stacks
  • ability to transfer stacks between inventorys(bank,backpack) but alsow between slots

this is what I am trying currently

warning long scripy
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local ServerStorage = game:GetService("ServerStorage")
local ContentProvider = game:GetService("ContentProvider")

DataStore2 = require(script.DataStore2)
Inven = require(script.Inventory)
-------------------------------------
local datastores ={
	"WorldId",
	"X",
	"Y",
	"Z",

	"respawn",
	"died",

	"BrawlingXp",
	"ArcheryXp",
	"CastingXp",
	"RobustnessXp",
	"ArmorXp",
	"StrengthXp",

	"SmithingXp",
	"FletchingXp",
	"EnchantingXp",
	"MiningXp",
	"WoodcuttingXp",
	"FiremakingXp",

	"FishingXp",
	"FarmingXp",
	"HerbloreXp",
	"CookingXp",
	"CraftingXp",
	"WorshipingXp",

	"AgilityXp",
	"ThievingXp",
	"SlayingXp",
	"HuntingXp",
	"SummoningXp",
	"ConstructingXp",

	"QuestsProgress",

	"EqHead",	
	"EqBack",	
	"EqNeck",	 
	"EqAmmunition",
	"EqMain_Tool",	 
	"EqTorso",	
	"EqOff_Tool",
	"EqGloves",	
	"EqLegs",	 
	"EqRing",
	"EqFeet",	


	"Bac1",--backpack slot 1 item name
	"Bac1Q", -- quantity in backpackslot 1
	"Bac2",
	"Bac2Q",
	"Bac3",
	"Bac3Q",
	"Bac4",
	"Bac4Q",
	"Bac5",
	"Bac5Q",
	"Bac6",
	"Bac6Q",
	"Bac7",
	"Bac7Q",
	"Bac8",
	"Bac8Q",
	"Bac9",
	"Bac9Q",
	"Bac10",
	"Bac10Q",
	"Bac11",
	"Bac11Q",
	"Bac12",
	"Bac12Q",
	"Bac13",
	"Bac13Q",
	"Bac14",
	"Bac14Q",
	"Bac15",
	"Bac15Q",
	"Bac16",
	"Bac16Q",
	"Bac17",
	"Bac17Q",
	"Bac18",
	"Bac18Q",
	"Bac19",
	"Bac19Q",
	"Bac20",
	"Bac20Q",
	"Bac21",
	"Bac21Q",
	"Bac22",
	"Bac22Q",
	"Bac23",
	"Bac23Q",
	"Bac24",
	"Bac24Q",
	"Bac25",
	"Bac25Q",
	"Bac26",
	"Bac26Q",
	"Bac27",
	"Bac27Q",

	"Ban1",--itemname in bankslot 1
	"Ban1Q",--quantity of items in bankslot 1 
	"Ban2",
	"Ban2Q",
	"Ban3",
	"Ban3Q",
	"Ban4",
	"Ban4Q",
	"Ban5",
	"Ban5Q",
	"Ban6",
	"Ban6Q",
	"Ban7",
	"Ban7Q",
	"Ban8",
	"Ban8Q",
	"Ban9",
	"Ban9Q",
	"Ban10",
	"Ban10Q",
	"Ban11",
	"Ban11Q",
	"Ban12",
	"Ban12Q",
	"Ban13",
	"Ban13Q",
	"Ban14",
	"Ban14Q",
	"Ban15",
	"Ban15Q",
	"Ban16",
	"Ban16Q",
	"Ban17",
	"Ban17Q",
	"Ban18",
	"Ban18Q",
	"Ban19",
	"Ban19Q",
	"Ban20",
	"Ban20Q",
	"Ban21",
	"Ban21Q",
	"Ban22",
	"Ban22Q",
	"Ban23",
	"Ban23Q",
	"Ban24",
	"Ban24Q",
	"Ban25",
	"Ban25Q",
	"Ban26",
	"Ban26Q",
	"Ban27",
	"Ban27Q",
	"Ban28",
	"Ban28Q",
	"Ban29",
	"Ban29Q",
	"Ban30",
	"Ban30Q",
	"Ban31",
	"Ban31Q",
	"Ban32",
	"Ban32Q",
	"Ban33",
	"Ban33Q",
	"Ban34",
	"Ban34Q",
	"Ban35",
	"Ban35Q",
	"Ban36",
	"Ban36Q",
	"Ban37",
	"Ban37Q",
	"Ban38",
	"Ban38Q",
	"Ban39",
	"Ban39Q",
	"Ban40",
	"Ban40Q",
	"Ban41",
	"Ban41Q",
	"Ban42",
	"Ban42Q",
	"Ban43",
	"Ban43Q",
	"Ban44",
	"Ban44Q",
	"Ban45",
	"Ban45Q",
	"Ban46",
	"Ban46Q",
	"Ban47",
	"Ban47Q",
	"Ban48",
	"Ban48Q",
	"Ban49",
	"Ban49Q",
	"Ban50",
	"Ban50Q",
	"Ban51",
	"Ban51Q",
	"Ban52",
	"Ban52Q",
	"Ban53",
	"Ban53Q",
	"Ban54",
	"Ban54Q",
}
-------------------------------------------
DataStore2.Combine("DATA",
	"WorldId",
	"X",
	"Y",
	"Z",

	"respawn",
	"died",

	"BrawlingXp",
	"ArcheryXp",
	"CastingXp",
	"RobustnessXp",
	"ArmorXp",
	"StrengthXp",
	"SmithingXp",
	"FletchingXp",
	"EnchantingXp",
	"MiningXp",
	"WoodcuttingXp",
	"FiremakingXp",
	"FishingXp",
	"FarmingXp",
	"HerbloreXp",
	"CookingXp",
	"CraftingXp",
	"WorshipingXp",
	"AgilityXp",
	"ThievingXp",
	"SlayingXp",
	"HuntingXp",
	"SummoningXp",
	"ConstructingXp",

	"QuestsProgress",

	"EqHead",	
	"EqBack",	
	"EqNeck",	 
	"EqAmmunition",
	"EqMain_Tool",	 
	"EqTorso",	
	"EqOff_Tool",
	"EqGloves",	
	"EqLegs",	 
	"EqRing",
	"EqFeet",

	"Bac1",
	"Bac1Q",
	"Bac2",
	"Bac2Q",
	"Bac3",
	"Bac3Q",
	"Bac4",
	"Bac4Q",
	"Bac5",
	"Bac5Q",
	"Bac6",
	"Bac6Q",
	"Bac7",
	"Bac7Q",
	"Bac8",
	"Bac8Q",
	"Bac9",
	"Bac9Q",
	"Bac10",
	"Bac10Q",
	"Bac11",
	"Bac11Q",
	"Bac12",
	"Bac12Q",
	"Bac13",
	"Bac13Q",
	"Bac14",
	"Bac14Q",
	"Bac15",
	"Bac15Q",
	"Bac16",
	"Bac16Q",
	"Bac17",
	"Bac17Q",
	"Bac18",
	"Bac18Q",
	"Bac19",
	"Bac19Q",
	"Bac20",
	"Bac20Q",
	"Bac21",
	"Bac21Q",
	"Bac22",
	"Bac22Q",
	"Bac23",
	"Bac23Q",
	"Bac24",
	"Bac24Q",
	"Bac25",
	"Bac25Q",
	"Bac26",
	"Bac26Q",
	"Bac27",
	"Bac27Q",

	"Ban1",
	"Ban1Q",
	"Ban2",
	"Ban2Q",
	"Ban3",
	"Ban3Q",
	"Ban4",
	"Ban4Q",
	"Ban5",
	"Ban5Q",
	"Ban6",
	"Ban6Q",
	"Ban7",
	"Ban7Q",
	"Ban8",
	"Ban8Q",
	"Ban9",
	"Ban9Q",
	"Ban10",
	"Ban10Q",
	"Ban11",
	"Ban11Q",
	"Ban12",
	"Ban12Q",
	"Ban13",
	"Ban13Q",
	"Ban14",
	"Ban14Q",
	"Ban15",
	"Ban15Q",
	"Ban16",
	"Ban16Q",
	"Ban17",
	"Ban17Q",
	"Ban18",
	"Ban18Q",
	"Ban19",
	"Ban19Q",
	"Ban20",
	"Ban20Q",
	"Ban21",
	"Ban21Q",
	"Ban22",
	"Ban22Q",
	"Ban23",
	"Ban23Q",
	"Ban24",
	"Ban24Q",
	"Ban25",
	"Ban25Q",
	"Ban26",
	"Ban26Q",
	"Ban27",
	"Ban27Q",
	"Ban28",
	"Ban28Q",
	"Ban29",
	"Ban29Q",
	"Ban30",
	"Ban30Q",
	"Ban31",
	"Ban31Q",
	"Ban32",
	"Ban32Q",
	"Ban33",
	"Ban33Q",
	"Ban34",
	"Ban34Q",
	"Ban35",
	"Ban35Q",
	"Ban36",
	"Ban36Q",
	"Ban37",
	"Ban37Q",
	"Ban38",
	"Ban38Q",
	"Ban39",
	"Ban39Q",
	"Ban40",
	"Ban40Q",
	"Ban41",
	"Ban41Q",
	"Ban42",
	"Ban42Q",
	"Ban43",
	"Ban43Q",
	"Ban44",
	"Ban44Q",
	"Ban45",
	"Ban45Q",
	"Ban46",
	"Ban46Q",
	"Ban47",
	"Ban47Q",
	"Ban48",
	"Ban48Q",
	"Ban49",
	"Ban49Q",
	"Ban50",
	"Ban50Q",
	"Ban51",
	"Ban51Q",
	"Ban52",
	"Ban52Q",
	"Ban53",
	"Ban53Q",
	"Ban54",
	"Ban54Q"
)
-end of combine-----------------------------


function callRemote(player, Subject, value)  -- comunication towards client
	ReplicatedStorage.Core.Remotes.RemoteEvent:FireClient(player,Subject,value)
end



Players.PlayerAdded:Connect(function(player) ---- main setup 
	for i,v in pairs (datastores) do
		getfenv()[v] = DataStore2(v, player)
		local value = getfenv()[v]:Get(0)
		callRemote(player,v,value)

		getfenv()[v]:OnUpdate(function (value)callRemote(player,v,value)end)

	end
	WorldId = DataStore2("WorldId", player)
	WorldId:BeforeSave(function()
		WorldId:Set(game.PlaceId,player)
	end)
end)

function OnServerEvent(player,Subject,...)
	print(player,Subject,...)
	if Subject == "invenswap" then
		Inven.invenswap (player,...)
	end
end


ReplicatedStorage.Core.Remotes.RemoteEvent.OnServerEvent:Connect(OnServerEvent)```
Itemdictionary just in case, skills have something similary
	["Bronze_Coin"] = {
		["Description"] = "the main human currency",
		["BackpackStackSize"] = 1000,
		["BankStackSize"] = 10000,
		["Value"] = 1,
		["ModelId"] = 0,
		["ImageId"] = 0,
	},
	["Copper_Coin"] = {
		["Description"] = "the main human currency",
		["BackpackStackSize"] = 1000,
		["BankStackSize"] = 10000,
		["Value"] = 100,
		["ModelId"] = 0,
		["ImageId"] = 4230412396,
	},
	["Silver_Coin"] = {
		["Description"] = "the main human currency",
		["BackpackStackSize"] = 1000,
		["BankStackSize"] = 10000,
		["Value"] = 1000,
		["ModelId"] = 0,
		["ImageId"] = 0,
	},

	["Gold_Coin"] = {
		["Description"] = "the main human currency",
		["BackpackStackSize"] = 1000,
		["BankStackSize"] = 10000,
		["Value"] = 10000,
		["ModelId"] = 0,
		["ImageId"] = 0,
	},
	["Sword"] = {
		["Description"] = "a training sword",
		["BackpackStackSize"] = 1,
		["BankStackSize"] = 1,
		["Value"] = 0,
		["ModelId"] = 0,
		["ImageId"] = 711844382,
	},
}

MetaTable = { __index = function(table, key)
	return {["Description"] = "Item info is missing",
	["BackpackStackSize"] = "inf",
	["BankStackSize"] = "inf",
	["Value"] = 0,
	["ModelId"] = 0,
	["ImageId"] = 175158448}
end}

setmetatable(ItemDictionary,MetaTable)

return ItemDictionary```

for the XP part this works like a charm, easy to understand and to implement
but as mentioned above i am hesitant about the inventory system

I have played with a alternatives
keep in mind that I didn’t save my alternatives and this might have bugs

Alternative 1, tables
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local ServerStorage = game:GetService("ServerStorage")
local ContentProvider = game:GetService("ContentProvider")
local HttpService = game:GetService("HttpService")


DataStore2 = require(script.DataStore2)
Inven = require(script.Inventory)
-------------------------------------
local datastores ={
	"WorldId",
	"X",
	"Y",
	"Z",

	"respawn",
	"died",

	"BrawlingXp",
	"ArcheryXp",
	"CastingXp",
	"RobustnessXp",
	"ArmorXp",
	"StrengthXp",

	"SmithingXp",
	"FletchingXp",
	"EnchantingXp",
	"MiningXp",
	"WoodcuttingXp",
	"FiremakingXp",

	"FishingXp",
	"FarmingXp",
	"HerbloreXp",
	"CookingXp",
	"CraftingXp",
	"WorshipingXp",

	"AgilityXp",
	"ThievingXp",
	"SlayingXp",
	"HuntingXp",
	"SummoningXp",
	"ConstructingXp",

	"QuestsProgress",

}
-------------------------------------------
DataStore2.Combine("DATA",
	"WorldId",
	"X",
	"Y",
	"Z",

	"respawn",
	"died",

	"BrawlingXp",
	"ArcheryXp",
	"CastingXp",
	"RobustnessXp",
	"ArmorXp",
	"StrengthXp",
	"SmithingXp",
	"FletchingXp",
	"EnchantingXp",
	"MiningXp",
	"WoodcuttingXp",
	"FiremakingXp",
	"FishingXp",
	"FarmingXp",
	"HerbloreXp",
	"CookingXp",
	"CraftingXp",
	"WorshipingXp",
	"AgilityXp",
	"ThievingXp",
	"SlayingXp",
	"HuntingXp",
	"SummoningXp",
	"ConstructingXp",

	"QuestsProgress",

	"Backpack",
	"Bank",
	"Equiped"
)
------------------------------


function callRemote(player, Subject, value)  -- comunication towards client
	ReplicatedStorage.Core.Remotes.RemoteEvent:FireClient(player,Subject,value)
end



Players.PlayerAdded:Connect(function(player) ---- main setup 
	for i,v in pairs (datastores) do
		getfenv()[v] = DataStore2(v, player)
		local value = getfenv()[v]:Get(0)
		callRemote(player,v,value)

		getfenv()[v]:OnUpdate(function (value)callRemote(player,v,value)end)

	end
	WorldId = DataStore2("WorldId", player)
	WorldId:BeforeSave(function()
		WorldId:Set(game.PlaceId,player)
	end)

	local DefaultBackpack = {
		["1"]={["item"] = "",["Quantity"] = 0},
		["2"]={["item"] = "",["Quantity"] = 0},
		["3"]={["item"] = "",["Quantity"] = 0},
		["4"]={["item"] = "",["Quantity"] = 0},
		["5"]={["item"] = "",["Quantity"] = 0},
		["6"]={["item"] = "",["Quantity"] = 0},
		["7"]={["item"] = "",["Quantity"] = 0},
		["8"]={["item"] = "",["Quantity"] = 0},
		["9"]={["item"] = "",["Quantity"] = 0},
		["10"]={["item"] = "",["Quantity"] = 0},
		["11"]={["item"] = "",["Quantity"] = 0},
		["12"]={["item"] = "",["Quantity"] = 0},
		["13"]={["item"] = "",["Quantity"] = 0},
		["14"]={["item"] = "",["Quantity"] = 0},
		["15"]={["item"] = "",["Quantity"] = 0},
		["16"]={["item"] = "",["Quantity"] = 0},
		["17"]={["item"] = "",["Quantity"] = 0},
		["18"]={["item"] = "",["Quantity"] = 0},
		["19"]={["item"] = "",["Quantity"] = 0},
		["20"]={["item"] = "",["Quantity"] = 0},
		["21"]={["item"] = "",["Quantity"] = 0},
		["22"]={["item"] = "",["Quantity"] = 0},
		["23"]={["item"] = "",["Quantity"] = 0},
		["24"]={["item"] = "",["Quantity"] = 0},
		["25"]={["item"] = "",["Quantity"] = 0},
		["26"]={["item"] = "",["Quantity"] = 0},
		["27"]={["item"] = "",["Quantity"] = 0},
	}

	local Backpack = DataStore2("Backpack", player)
	backpackinv2 = Backpack:Get(DefaultBackpack)
	--print(backpackinv2)
	--Backpack:Set(DefaultBackpack)
	callRemote(player,backpackinv2)
	Backpack:OnUpdate(function (value)callRemote(player,backpackinv2)end)

	local DefaultBank = {
		["1"]={["item"] = "",["Quantity"] = 0},
		["2"]={["item"] = "",["Quantity"] = 0},
		["3"]={["item"] = "",["Quantity"] = 0},
		["4"]={["item"] = "",["Quantity"] = 0},
		["5"]={["item"] = "",["Quantity"] = 0},
		["6"]={["item"] = "",["Quantity"] = 0},
		["7"]={["item"] = "",["Quantity"] = 0},
		["8"]={["item"] = "",["Quantity"] = 0},
		["9"]={["item"] = "",["Quantity"] = 0},
		["10"]={["item"] = "",["Quantity"] = 0},
		["11"]={["item"] = "",["Quantity"] = 0},
		["12"]={["item"] = "",["Quantity"] = 0},
		["13"]={["item"] = "",["Quantity"] = 0},
		["14"]={["item"] = "",["Quantity"] = 0},
		["15"]={["item"] = "",["Quantity"] = 0},
		["16"]={["item"] = "",["Quantity"] = 0},
		["17"]={["item"] = "",["Quantity"] = 0},
		["18"]={["item"] = "",["Quantity"] = 0},
		["19"]={["item"] = "",["Quantity"] = 0},
		["20"]={["item"] = "",["Quantity"] = 0},
		["21"]={["item"] = "",["Quantity"] = 0},
		["22"]={["item"] = "",["Quantity"] = 0},
		["23"]={["item"] = "",["Quantity"] = 0},
		["24"]={["item"] = "",["Quantity"] = 0},
		["25"]={["item"] = "",["Quantity"] = 0},
		["26"]={["item"] = "",["Quantity"] = 0},
		["27"]={["item"] = "",["Quantity"] = 0},
		["28"]={["item"] = "",["Quantity"] = 0},
		["29"]={["item"] = "",["Quantity"] = 0},
		["30"]={["item"] = "",["Quantity"] = 0},
		["31"]={["item"] = "",["Quantity"] = 0},
		["32"]={["item"] = "",["Quantity"] = 0},
		["33"]={["item"] = "",["Quantity"] = 0},
		["34"]={["item"] = "",["Quantity"] = 0},
		["35"]={["item"] = "",["Quantity"] = 0},
		["36"]={["item"] = "",["Quantity"] = 0},
		["37"]={["item"] = "",["Quantity"] = 0},
		["38"]={["item"] = "",["Quantity"] = 0},
		["39"]={["item"] = "",["Quantity"] = 0},
		["40"]={["item"] = "",["Quantity"] = 0},
		["41"]={["item"] = "",["Quantity"] = 0},
		["42"]={["item"] = "",["Quantity"] = 0},
		["43"]={["item"] = "",["Quantity"] = 0},
		["44"]={["item"] = "",["Quantity"] = 0},
		["45"]={["item"] = "",["Quantity"] = 0},
		["46"]={["item"] = "",["Quantity"] = 0},
		["47"]={["item"] = "",["Quantity"] = 0},
		["48"]={["item"] = "",["Quantity"] = 0},
		["49"]={["item"] = "",["Quantity"] = 0},
		["50"]={["item"] = "",["Quantity"] = 0},
		["51"]={["item"] = "",["Quantity"] = 0},
		["52"]={["item"] = "",["Quantity"] = 0},
		["53"]={["item"] = "",["Quantity"] = 0},
		["54"]={["item"] = "",["Quantity"] = 0},
	}
	local Bank = DataStore2("Bank", player)
	Bankinv2 = Bank:Get(DefaultBank)
	--print(backpackinv2)
	--Bank:Set(DefaultBank)
	callRemote(player,Bankinv2)
	Bank:OnUpdate(function (value)callRemote(player,Bankinv2)end)

	local DefaultEquiped ={
		["Head" ]= "",
		["Back" ]= "",
		["Neck" ]= "",
		["Ammunition"]= "",
		["Main_Tool" ]= "",
		["Torso" ]= "",
		["Off_Tool"]= "",
		["Gloves" ]= "",
		["Legs"]= "",
		["Ring"]= "",
		["Feet"]= "",
	}

	local Equiped = DataStore2("Equiped", player)
	Equipedinv2 = Equiped:Get(DefaultEquiped)
	--print(Equipedinv2)
	--Equiped:Set(DefaultEquiped)
	callRemote(player,Equipedinv2)
	Bank:OnUpdate(function (value)callRemote(player,Equipedinv2)end)

end)

function OnServerEvent(player,Subject,...)
	print(player,Subject,...)
	if Subject == "invenswap" then
		Inven.invenswap (player,...)
	end
end


ReplicatedStorage.Core.Remotes.RemoteEvent.OnServerEvent:Connect(OnServerEvent)

my question is :
based on Datastore2. what would be the best way to manage a inventory system.

i know other people have simulair issues,
ended up reading most of the messages here, watching the alvin blox video and RDC 2019
going to the github yet my doubt prevails

Just a question, do you need to add a Players.PlayerRemoved function for the data to save on leave. I’m unsure of when else data other than when you specifically update it. If that makes any sense.

No, it is not needed. The data is saved everytime it is updated

no the scripts saves when people leaves

Hello, I am not too sure about this but can I have different places within the same game but I do not include some of the data? Not too good at explaining this but I give you an example

--Start Place
DataStore2.Combine("Data", "Cash", "Stats1", "Stats2")

--Place 2
DataStore2.Combine("Data", "Cash", "Stats1")

--Place 3
DataStore2.Combine("Data", "Cash", "Stats2")

So is this possible?

1 Like

That works out fine, yeah.

3 Likes

I have one more question. Is there any difference between saving by UserId and saving by Player? Like if you save by Player, and the player changes their Username, will their data still be the same?

People prefer to use a players userid. If you use their username, you risk them changing it and it will be removed.

Basically, Userid: Works either way if the person has switched username.

I meant as in save by Player and not Username

Edit: By player I meant like when you do a

game.Players.PlayerAdded:Connect(function(player)

and you get that player

1 Like

I don’t know what you mean by “save by player”–you don’t need to think about user IDs at all when using DataStore2.

2 Likes

So if a save using the method you provided in the example at GitHub and the player changes their name, they would not have any data loss right?

DataStore2 its best module ever, but i have a HUGE problem. Everytime when im using/editing data and leaving from Play Mode in studio. My studio crashes with error like.
“Script that called a callback was destroyed”.
No useful info in “More Info”. So i just need keep restarting my studio to test scripts. ;C.

Try create an autosave script.

I just realised there’s a :GetTable, however I’ve been using :Get with tables as I thought this was the only way. Is there an issue if I were to use :Get for tables instead of :GetTable? Is there any disadvantages to this?

No, not much. You can still use :Get() and it should work fine.

1 Like

Here is part of the DataStore2 api about GetTable

DataStore:GetTable

GetTable(default: Dictionary<any, any>) → Dictionary<any, any>
Will get the value (either from the cache or Roblox data stores), and patch it with the default value if it doesn’t have the keys. For example, if you have the data:

{
coins = 0,
swords = {},
}
…and want to add a gems field, just appending on that to the default value for Get won’t work the way you might want it too–it won’t add the key!

– Oops! The player already has data, so it doesn’t try to use the default value!
dataStore:Get({
coins = 0,
gems = 0,
swords = {},
})
You can, however, use GetTable:

– Much better! It’ll check if they have each key rather than just if they have data.
dataStore:GetTable({
coins = 0,
gems = 0,
swords = {},
})
Note

This is not necessary to use tables with DataStore2. You can save/retrieve tables just like any other piece of data.

2 Likes

How do I save bools and strings? I wanna know what I use is it Increment?

Please read the documentation. These are extremely basic questions answered in detail.

2 Likes

I can’t find anything about bools or strings??? Where is it.

1 Like

Why i get this error? I know it appears when i request too many DataStore Requests, but…

Screenshot_311

It happens here:

DataService:Increment(player, "Gold", reward)
DataService:Increment(player, "TotalGold", reward)
DataService:Increment(player, "TotalKills", 1)

Also later (like second after thing above) i do:

DataService:Set(player, "Items", newtable)

How this functions looks like inside DataService Module:

function DataService:Set(plr, store, value)
    local success, result = pcall(function()
    	DataStore2(store, plr):Set(value)
    end)

	if not success then
		warn(result)
	end
end`


function DataService:Increment(plr, store, value)
	local success, result = pcall(function()
		DataStore2(store, plr):Increment(value)
	end)

	if not success then
		warn(result)
	end
end

When player logins i get his data (so it should be inside cached table inside DS2), and so after i change it like set new data, or add numbers, this isn’t supposed to do DataStore calls and so no yield, but i get this yield. Why is this happening?