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

Hello! I’m using datastore2 a lot and is wonderful but I still with this problem I don’t know what else to do please help :pray:

From what I can tell using both of them is not practical, the only time you should use datastore2 and a normal datastore is when you have a leaderboard of some sort which will need the normal datastore for it to work, as I don’t think DataStore2 is compatible with a leaderboard. If you don’t plan to have a leaderboard then I would say stick to dataStore2 as it is really reliable. I’m no expert with datastores, and or scripting for that matter, but I do think using both datastores in a game is just unnecessary and wouldn’t be good for the server especially if the game gets a lot of attraction.

Does anyone know what’s up with this error, I get it when I try buying a developer product that’s suppose to Incremente my coins.

Error: [ServerScriptService.DataStore2:479: DataStore2() API call expected {string dataStoreName, Instance player}, got {string, nil}

Script for Dev Product:

local MarketplaceService = game:GetService(“MarketplaceService”)
local SeverScriptService = game:GetService(“ServerScriptService”)
local DataStore2 = require(SeverScriptService:WaitForChild(“DataStore2”))
local DrachmaId1 = 1020030204 --1000 Drachma
local DrachmaId2 = 1020143993 --5000 drachma
local DrachmaId3 = 1020148147 --10,000 drachma
local DrachmaId4 = 1020151919 --20,000 drachma
local DrachmaId5 = 1020150864 – 40,000 drachma
local Players = game:GetService(“Players”)
local Pler = Players.LocalPlayer

DataStore2.Combine(“DATA”, “CoinStore”)
local function processReceipt(receiptInfo, Plr)
local player = game:GetService(“Players”):GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet

end
 if receiptInfo.ProductId == DrachmaId1 then
	
print(player.Name.. "just bought" .. receiptInfo.ProductId)
	
local CoinStore = DataStore2("CoinStore", Pler)
	CoinStore:Increment(1000)
--player.Cosas.Coins.Value = player.Cosas.Coins.Value + 1000

end

if receiptInfo.ProductId == DrachmaId2 then
	
print(player.Name.. "just bought" .. receiptInfo.ProductId)
	local CoinStore = DataStore2("CoinStore", Pler)
	CoinStore:Increment(5000)
--player.Cosas.Coins.Value = player.Cosas.Coins.Value + 5000

end

if receiptInfo.ProductId == DrachmaId3 then
	
print(player.Name.. "just bought" .. receiptInfo.ProductId)
	
	local CoinStore = DataStore2("CoinStore", Pler)
	CoinStore:Increment(10000)
--player.Cosas.Coins.Value = player.Cosas.Coins.Value + 10000

end

if receiptInfo.ProductId == DrachmaId4 then
	
print(player.Name.. "just bought" .. receiptInfo.ProductId)
	local CoinStore = DataStore2("CoinStore", Pler)
	CoinStore:Increment(20000)
--player.Cosas.Coins.Value = player.Cosas.Coins.Value + 20000

end

if receiptInfo.ProductId == DrachmaId5 then
	
print(player.Name.. "just bought" .. receiptInfo.ProductId)
	local CoinStore = DataStore2("CoinStore", Pler)
	CoinStore:Increment(45000)
player.Cosas.Coins.Value = player.Cosas.Coins.Value + 45000

end

return Enum.ProductPurchaseDecision.PurchaseGranted
end

MarketplaceService.ProcessReceipt = processReceipt

Your error is here. Please read through your code and make sure you are using the API correctly.

1 Like

Nvm I figured it out. I changed the “Pler”-which equaled game.Players.LocalPlayer. To “player”(game:GetService(“Players”):GetPlayerByUserId(receiptInfo.PlayerId)). That seems to have fixed it.

1 Like

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