Awhile back I worked on a DS module with the help of this forum - So far it factors for all the values shown below & saves them. I was wondering how / if I could implement a method of saving {all} Color3 values and / or all Vector3 values within the set folder.
local System = {}
local DataStoreService = game:GetService("DataStoreService")
local DSS = DataStoreService:GetDataStore("DataStoreService", 0.01)
function System.DataSave(Player)
local success, Data = pcall(function()
return DSS:SetAsync(Player.UserId, saveToDictionary(Player["PlayerData"]))
end)
if success then
print("Saved!")
else
print("Failed!")
end
end
function System.DataLoad(Player)
local success, Data = pcall(function()
return DSS:GetAsync(Player.UserId)
end)
if success then
if Data then
print("Old Data Loaded")
local PlayerDataFolder = materializeDictionary(Data)
PlayerDataFolder.Name = "PlayerData"
PlayerDataFolder.Parent = Player
else
print("New Data Loaded")
local PlayerDataFolder = script["Template"]:Clone()
PlayerDataFolder.Name = "PlayerData"
PlayerDataFolder.Parent = Player
System.DataSave(Player)
end
end
end
function saveToDictionary(object)
if not object:IsA("Configuration") then
return object.Value
else
local newTable = {}
for i,v in pairs(object:GetChildren()) do
newTable[v.Name] = saveToDictionary(v)
end
return newTable
end
end
function materializeDictionary(input)
if typeof(input) == "table" then
local newFolder = Instance.new("Configuration")
for i,v in pairs(input) do
local newObject = materializeDictionary(v)
newObject.Name = i
newObject.Parent = newFolder
end
return newFolder
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
elseif typeof(input) == "boolean" then
local newBoolValue = Instance.new("BoolValue")
newBoolValue.Value = input
return newBoolValue
end
end
return System