Datastore2 doesn't save all folders

Got this Datastore2 Script:

local datatable = game.ServerStorage.Data --gets a folder that stores the player data

local Datastore2 = require(script.DataStore2Module)

Datastore2.Combine("MainKey")

local function savefunction(plr,v)

	local tab = {}

	if v then
		for e,a in pairs(v:GetChildren()) do
			tab[a.Name]= a.Value
		end
	end
	return tab
end



Datastore2.Combine("MasterKey")

local function plradded(plr)
	for i,v in pairs(datatable:GetChildren()) do
		
		local folder = v:Clone()
		folder.Parent = plr
		
		local data = Datastore2(v.Name,plr)

		local save
		local succ,err = pcall(function()
			save=data:Get()
		end)

		if succ then

			-- Loads Save
			if save then
				for e,a in pairs(folder:GetChildren()) do
					if save[a.Name] then
						a.Value = save[a.Name]
					end
				end
			end

			-- Save Data when Updates
			for _,plrdata in pairs(folder:GetChildren()) do
				plrdata.Changed:connect(function()
					data:Set(savefunction(plr,folder))
				end)
			end

		end

		if not succ then
			print(err)
		end
	end

end

game.Players.PlayerAdded:Connect(plradded)

for i,v in pairs(game.Players:GetPlayers()) do
	spawn(function()
		plradded(v)
	end)
end

image
AnsweredPhone and Donated gets saved and loaded correctly, The other values aren’t. Any ideas? Thanks for reading.
I added some print statements and I believe it doesn’t save values that are set to false. By default the settings are all true and hasDone is false.

Fixed it by changing a line

if save[a.Name] ~= nil then

instead of

if save[a.Name] then 

because save[a.Name] could be false

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.