I want to make a datastore system that's inside a module.
I've heard that people use modules for DataStores since its simple., but I'm not sure how they do it. I did go through the forums and found one example, but all of the others are too complex for me to work with, as I don't understand what they're doing.The one example I looked through showed a simple way to use data stores, but I can’t really be flexible with it since it requires you to save with server scripts and I’m trying to save it on local scripts. I did rewrite everything so that it would be flexible with tables, but I’m not sure if it works since it’s not on a server script. I can provide the module that I’m working on.
DataStore Module:
local data = {}
local DataStoreService = game:GetService("DataStoreService")
function data.LoadData(Player, Value, valueName)
print(Value)
local dataStore = DataStoreService:GetDataStore(valueName)
local data
local success, errorMessage = pcall(function()
data = dataStore:GetAsync(Player.UserId .. "_" .. valueName)
end)
if success and data then
for i, newValue in Value do
newValue.Value = data[i]
print(newValue.Value,data[i])
end
else
print(errorMessage)
print(data)
end
end
function data.SaveData(Player, Value, valueName)
local dataStore = DataStoreService:GetDataStore(valueName)
local success, errorMessage = pcall(function()
data = dataStore:SetAsync(Playe`Preformatted text`r.UserId .. "_" .. valueName)
end)
if success then
print("Successfully saved " .. Player .. "'s Data")
end
end
function data.BindToClose(Value)
print("Not Working")
end
return data