I’ve finished the module completely, but there is one thing, getting the data, I have NO idea how to do this. (help)
Review the script I guess, (skip to getData at the bottom if you want)
local DSSfunc = {}
local DSS = game:GetService("DataStoreService")
local LogService = game:GetService("LogService")
local Players = game.Players
function DSSfunc:CreateDataStore(Name)
DSS:GetDataStore(Name)
end
function DSSfunc:AddFolder(InstanceName)
local NewFolder = Instance.new("Folder")
NewFolder.Name = InstanceName
NewFolder.Parent = game.ReplicatedStorage
end
function DSSfunc:AddValue(InstanceType, InstanceName, FolderName)
if InstanceType == "BoolValue" then
local BoolValue = Instance.new("BoolValue")
BoolValue.Parent = game.ReplicatedStorage:WaitForChild(FolderName)
BoolValue.Name = InstanceName
elseif InstanceType == "StringValue" then
local StringValue = Instance.new("StringValue")
StringValue.Parent = game.ReplicatedStorage:WaitForChild(FolderName)
StringValue.Name = InstanceName
elseif InstanceType == "NumberValue" then
local NumberValue = Instance.new("NumberValue")
NumberValue.Parent = game.ReplicatedStorage:WaitForChild(FolderName)
NumberValue.Name = InstanceName
end
end
function DSSfunc:SaveData(PlayerInstance, FolderToSave, cDataName)
local success, errormsg = pcall(function()
local Store = DSS:GetDataStore(cDataName)
local TableToSave = {}
for _,data in pairs(FolderToSave:GetChildren()) do
table.insert(TableToSave, data.Value)
end
Store:SetAsync(PlayerInstance, TableToSave)
end)
if success then
print("Data saved successfully!")
else
print("Oof! Data was not able to save!")
warn(errormsg)
end
end
function DSSfunc:GetData(PlayerInstance, FolderToGet, cDataName)
local data
local success, errormsg = pcall(function()
local Store = DSS:GetDataStore(cDataName)
data = Store:GetAsync(PlayerInstance)
local TableToGet = {}
for _,data1 in pairs(FolderToGet:GetChildren()) do
table.insert(TableToGet, data1.Value)
end
end)
if success and data then
print("Data retrieved successfully")
-- this part is annoying
else
print("Player has no data")
end
end
return DSSfunc