I am using datastore2 for the first time and I want to save data from a folder, is it right or wrong? As I understand it, am I creating many “DataStore2.Combine” or am I wrong?
I would appreciate your support
local DataStore2 = require(Modules:WaitForChild("DataStore2"))
-- Function to configure values and listen for changes
local function setupStatValue(statValue)
local dataStoreKey = statValue.Name
print(dataStoreKey)
local valueData = {
Name = statValue.Name,
Value = DataStore2(dataStoreKey, Player):Get() or statValue.Value
}
local dataStore = DataStore2(dataStoreKey, Player)
statValue.Value = valueData.Value
statValue.Changed:Connect(function(NewValue)
valueData.Value = NewValue
dataStore:Set(NewValue)
end)
end
-- Configure settings and listen for changes for all folders and settings
for _, folder in ipairs(CEditor:GetChildren()) do
if folder:IsA("Folder") then
for _, statValue in ipairs(folder:GetChildren()) do
if statValue:IsA("StringValue") or statValue:IsA("IntValue") or ("NumberValue") then
setupStatValue(statValue)
end
end
end
end