Problems with Data Store 2

Hello guys, I’m working on a game and I wanna use data store 2. I’m experimenting with data store 2 and I made this script


local ds2 = require(game.ServerScriptService.DataStore2)
ds2.Combine("Data","Coins","Gems","TotalSnow","Blowers","BackPacks")
game.Players.PlayerAdded:Connect(function(player)
	wait(1)
	local UserId = player.UserId
	local stats = player.leaderstats
	local Coins = stats.Coins
	local TotalSnow = stats.TotalSnow
	local blowers = player.Items.Blowers:GetChildren()
	local BackPacks = player.Items.BackPacks:GetChildren()
	local Gems = player.leaderstats.Gems
	-- load data

	local TotalSnowdataStore = ds2("TotalSnow",player)
	local CoinsDataStore = ds2("Coins",player)
	local GemsDataStore = ds2("Gems",player)
	local dataBlowersStore =  ds2("Blowers",player)
	local dataBackPacksStore = ds2("BackPacks",player)
	TotalSnow.Value = TotalSnowdataStore:Get(0)
	Coins.Value = CoinsDataStore:Get(0)
	Gems.Value = GemsDataStore:Get(0)
	for _, tbl in pairs(dataBlowersStore) do
		local getfolder = blowers[tbl[3]]
		if getfolder ~= nil then
			getfolder.Equipt.Value, getfolder.Purchased.Value = tbl[1], tbl[2]
			print(getfolder.Equipt.Value)
		end
	end
	for _, tbl in pairs(dataBackPacksStore) do
		local getfolder = BackPacks[tbl[3]]
		if getfolder ~= nil then
			getfolder.Equipt.Value, getfolder.Purchased.Value = tbl[1], tbl[2]
			print(getfolder.Equipt.Value)
		end
	end
	TotalSnowdataStore:OnUpdate(function(NewValue)
		print("Value Updates",NewValue)
		TotalSnow.Value = NewValue
	end)
	CoinsDataStore:OnUpdate(function(NewValue)
		print("Value Updates",NewValue)
		Coins.Value = NewValue
	end)
	GemsDataStore:OnUpdate(function(NewValue)
		print("Value Updates",NewValue)
		Gems.Value = NewValue
	end)
	dataBackPacksStore:OnUpdate(function(NewValue)
		print("Value Updates",NewValue)
		dataBlowersStore:OnUpdate(function(NewValue)
			print("Value Updates",NewValue)
		end)
	end)
end)
while wait(5) do
	for i,player in pairs(game.Players:GetChildren()) do
		local BlowerStore = ds2("Blowers",player)
		local BackPackStore = ds2("BackPacks",player)
		local tableToStoreBlowers = {}
		for _, blower in pairs(player.Items.Blowers:GetChildren()) do
			table.insert(tableToStoreBlowers, {blower.Equipt.Value, blower.Purchased.Value, blower.Name})
		end
		local tableToStoreBackPacks = {}
		for _, Backpack in pairs(player.Items.BackPacks:GetChildren()) do
			table.insert(tableToStoreBackPacks, {Backpack.Equipt.Value, Backpack.Purchased.Value, Backpack.Name})
		end
		BlowerStore:Set(tableToStoreBlowers)
		BackPackStore:Set(tableToStoreBackPacks)
	end
end

It isn’t working, probably because of a stupid reason. Can someone help me out? Thanks.

you should probably link the module so people can see the functions

This is just in a server script. The only module is the data store 2 module. Should I put it in a module script?

I ment the Datastore2 module so people can see its code because your code has

local ds2 = require(game.ServerScriptService.DataStore2)

and what is the DataStore2 module as its not a normal Datastore service.

Okay
DataStore2.rbxm (17.9 KB)
Here it is for anyone who needs to look at it.

Here is the api if anyone needs it
https://kampfkarren.github.io/Roblox/api/

Is there any errors?
Did you save anything to the DataStore?

Bro. Its data store 2. How do you not know datastore2? But anyways…

I stick with using the original because its just better in general and doesn’t use extra junk.

I don’t see any “junk” in data store 2, I only use normal data stores because I’m used to them, calling it “junk” is very disrespectful to the dev who made it which btw did an awesome job.

1 Like

Okay I guess I will revert back to the original for now until I can fix data store 2.

I think your issue isn’t data store 2 specifically, here’s the thing, data store 2 works on a way that, you change not the leaderstats value and stuff, but you change the datastore2 value, so instead of doing

plr.leaderstats.Gems.Value += 10

you would do

local gemsStore = ds2("Gems", plr)
gemsStore:Increment(10)

If you wanna make it the leaderstats way, you can change the data store value each time the value changes instead. And remove the part on updated.

Example:

gems:GetPropertyChangedSignal("Value"):Connect(function()
    gemsStore:Set(gems.Value)
end)

Also, do you have a SaveInStudio value on ServerStorage? You need to have a Bool Value inside ServerStorage called SaveInStudio and enabled to true. Else it won’t save on studio like the name implies

Okay I will try that, and yes I do have save in studio enabled. What I am really stuck on is how I would serialize data into data store 2. I already have it somewhat set up in the script above.

1 Like