I made the this thing hoping to store data within a ModuleScript, any potential improvements?
local Loader = require(script.Parent.Parent.ModuleLoader)
local DataFunctions = Loader:Load("DataFunctions")
local Data = Loader:Load("DefaultData")
local Default = Data.DefaultData
local Module = {}
local Metatable = {}
local Prototype = Default
Metatable.__index = Prototype;
function Module.new(Player)
Module[Player.Name] = {}
local NewIndex = Module[Player.Name]
local self = setmetatable({}, NewIndex)
return self
end
function Metatable.Initialize(self, Player)
local Key = "id_" .. Player.userId
if not Data.DataStore:GetAsync(Key) then
Save(Key, Default)
self = Default
else
local Data = Load(Key)
self = Data
end
return self
end
Module.Metatable = Metatable;
return Module;