Datastore 2 not saving?

local data = {}

local HttpService = game:GetService("HttpService")
local players = game:GetService("Players")

local Datastore2 = require(1936396537) -- Get datastore2 module
Datastore2.Combine("Inventory", "Gold", "Armour", "Potions", "Weapons","Health","Damage","MagicDamage","Level", "Experience","MaxExperience" )

data.AddedEvent = function(player)
	--// Inventory System
	local Inventory ="Folder", player); Inventory.Name = "Inventory"
	local playerGold ="IntValue", Inventory); playerGold.Name = "Gold"
    local playerArmour ="StringValue", Inventory); playerArmour .Name = "Armour"
    local playerPotions ="StringValue", Inventory); playerPotions .Name = "Potions"
	local playerWeapons ="StringValue", Inventory); playerWeapons .Name = "Weapons"
	--// Player Stats
	local playerHealth ="IntValue", Inventory); playerHealth.Name = "Health"
	local playerDamage ="IntValue", Inventory); playerDamage.Name = "Damage"
	local playerMagicDmg ="IntValue", Inventory); playerMagicDmg.Name = "MagicDamage"
	--// Players Level
	local LevelSystem ="Folder", player); LevelSystem.Name = "LevelSystem"
	local PlayerLevel ="IntValue", LevelSystem); PlayerLevel.Name = "Level"
	local PlayerXp ="IntValue", LevelSystem); PlayerXp.Name = "Experience"
	local PlayerMaxXp ="IntValue", LevelSystem); PlayerMaxXp.Name = "MaxExperience" 
	--// Datastore 
    local goldStore = Datastore2("Gold", player); local goldStoreData = goldStore:Get()
    local armourStore = Datastore2("Armour", player); local armourStoreData = armourStore:Get({ })
    local potionsStore = Datastore2("Potions", player); local potionsStoreData = potionsStore:Get({ })
	local weaponsStore= Datastore2("Weapons", player); local weaponsStoreData = weaponsStore:Get({ })
	local healthStore = Datastore2("Health", player); local healthStoreData = healthStore:Get()
	local damageStore = Datastore2("Damage", player); local damageStoreData = damageStore:Get()
	local magicStore = Datastore2("MagicDamage", player); local magicStoreData = magicStore:Get()
	local levelStore = Datastore2("Level", player); local levelStoreData = levelStore:Get()
	local xpStore = Datastore2("Experience", player); local XpStoreData = xpStore:Get()
	local maxxpStore = Datastore2("MaxExperience",player); local MaxXpStoreData = maxxpStore:Get()
	--// JSON Encode/Decode
    playerArmour.Value = HttpService:JSONEncode(armourStoreData) -- Turning your items into a JSON table. we don't need to do this for gold as gold is a number and wont have multiple items inside
         playerArmour.Value = HttpService:JSONEncode(decodedData) -- Encodes newly updated data

    playerPotions.Value = HttpService:JSONEncode(potionsStoreData) 
         playerPotions.Value = HttpService:JSONEncode(decodedData) -- Encodes newly updated data
    playerWeapons.Value = HttpService:JSONEncode(weaponsStoreData) 
         playerWeapons.Value = HttpService:JSONEncode(decodedData) -- Encodes newly updated data

return data

This is a dataStore2 Module script and I have it being called from a serverscriptservice, and for some reason when I leave the game my values don’t save? It says Inventory saved but nothing really does save, I also have a boolValue in serverStorage called SaveInStudio, set to true but Nothing saves, I usually change my values on the server and then leave to see if they save but they dont. Any reason or am I just being stupid right now. Below is the serverSriptService script.

local players = game:GetService("Players")

local data = require(game.ServerStorage:WaitForChild("Modules"):WaitForChild("DataStoreHandler"))




Could it be related to this ongoing bug?

Others have reported issues with DataStore2 on that thread. Are you getting any of the errors listed on that thread?


Why are you involving HttpService and JSONEncode here???
Not necessary for tables to be encoded before being saved, or even to encode and then decode values each time the value in the store changes.

Also, this isn’t the latest version since the module isn’t maintained on the website, get it from

Where would I have the HttpSevice and JSONEcode? I recently asked this on my recent post and someone sent me this, I also tried the datastore2 you linked, still doesn’t work, also Isn’t require(1936396537) always the updated version? Sorry for asking a lot of questions.

No it isn’t, kampfkarren will probably have to change or remove that comment (they know about it through the main thread), you don’t really need JSONEncode here because when you attempt to store tables they get encoded into strings internally since you can only save strings to the database.

Edit: You don’t even need this here, there’s a reason why JSONEncode isn’t a function of DataStoreService.

You can save tables just simply by

DataStore:SetAsync(key, {})

Edit 2:

yes, that’s right.

So if I have a weapon with stats, lets say a sword has 12 damage and you upgrade it into 14 damage or something like that, wouldn’t it be better to use JSONEncode, or no could I just save it in a table somehow.

So if I do something like this:

local player_save_table = {
	['EquippedSword'] = Default,
	['Damage'] = 10,

Would this be similar say I have a sword and upgrade would I have something like this which saves the value of the sword.

I don’t get errors, when I leave it says, Player left, inventory saved.

1 Like