Currently, my DataStore is capable of saving // restoring all values within a given folder - However, the format only works if the Values are direct children of the Folder / Configuration being changed as such.

https://doy2mn9upadnk.cloudfront.net/uploads/default/original/4X/1/8/e/18ef1aeeee72e99b372f9d69a00f8c3f8c884607.png

Below is what I wish to achieve:

https://doy2mn9upadnk.cloudfront.net/uploads/default/original/4X/9/4/b/94b568ad9b0775b3c5537f1eafc6d33dd6214f2c.png

I wish to maintain the over-all Save function in which it is capable of saving everything rather than looking for a labelled specific value. I have included the coding.

SaveData:

	local success, Data = pcall(function()
		return DataStoreService:SetAsync(Player.UserId, saveToDictionary(Player["PlayerData"]))
	end)
	if success then end
end

function saveToDictionary(object)
	if not object:IsA("Configuration") then
		if (object:IsA("Color3Value")) then
			return { "Color3", tostring(object.Value) }
		end
		return object.Value
	else
		local newTable = {}
		for i,v in pairs(object:GetChildren()) do
			newTable[v.Name] = saveToDictionary(v)
		end
		return newTable
	end

LoadData:

function materializeDictionary(input)
	if typeof(input) == "table" then
		if (input[1] == "Color3") then
			local newColor3Value = Instance.new("Color3Value")
			newColor3Value.Value = Color3.new(unpack(input[2]:split(", ")))
			return newColor3Value
		end
	
	local newConfig = Instance.new("Configuration")
	for i,v in pairs(input) do
		local newObject = materializeDictionary(v)
		newObject.Name = i
		newObject.Parent = newConfig
		end
	return newConfig
	
	elseif typeof(input) == "number" then
		local newIntValue = Instance.new("NumberValue")
		newIntValue.Value = input
		return newIntValue
	elseif typeof(input) == "string" then
		local newStringValue = Instance.new("StringValue")
		newStringValue.Value = input
		return newStringValue
	elseif typeof(input) == "boolean" then
		local newBoolValue = Instance.new("BoolValue")
		newBoolValue.Value = input
		return newBoolValue
	end
end

1 comment

0

For SaveData you should be able to use GetDescendants instead of GetChildren, but I'm not sure how to put it in the right place in LoadData.