Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[Advanced] Datastore2 not saving?

I posted a previous question about my datastore and was recommended to migrate over to datastore2, but it's not saving and I'm not sure why, this is first time using datastore2 so don't trash me on my code, I kinda got the gist of what to do from a devforum article.

local DataStore2 = require(1936396537)

local leaderstats1 = {
	["Level"] = 0,
	["XP"] = 0,
	["MaxHealth"] = 120,
	["Qalium"] = 0,
	["HealthP"] = 0,
	["SwordP"] = 0,
	["MeleeP"] = 0,
	["ClassP"] = 0,
	["Points"] = 0,
	["Tries"] = 10,
}
local leaderstats2 = {
	["Element"] = "",
	["Sign"] = "",
}

DataStore2.Combine("MasterKey","Qalus")

local function savedata(folder)
	local tab = {}
		for i,v in pairs(folder:GetChildren()) do
			tab[v.Name]= v.Value
	end
	return tab
end

game.Players.PlayerAdded:Connect(function(plr)
local	datastore = DataStore2("Data",plr)

	local folder = Instance.new("Folder", plr) folder.Name = "leaderstats1"
	
	for i,v in pairs(leaderstats1) do
		local intval = Instance.new("NumberValue",folder)
		intval.Name = i
		intval.Value = v
	end
	
	for i,v in pairs(leaderstats2) do
		local intval2 = Instance.new("StringValue",folder)
		intval2.Name = i
		intval2.Value = v
	end
	
	
	local data = datastore:Get()
	
	if data ~= nil then
		for i,v in pairs(data) do
			if folder:FindFirstChild(i) then
				folder[i].Value = v
			end
		end
	end
	for i,v in pairs(folder:GetChildren()) do
		v.Changed:connect(function()
			local tab = savedata(folder)
			datastore:Set(tab)
		end)
	end
end)

1 answer

Whoever recommended Datastore2 may not have said some very crucial things, and may have actually left a lot of important information out.

Personally, the use of ROBLOX Datastore is more reliable, or the use of your own Database to store data for your game.

If you insist on using Datastore2 I will link a YouTube Tutorial about it here.

Datastore2 is old as well.

This discussion is preserved as it was. New answers, comments, and votes are closed.