I have a ProfileService profiles manager for easy setting, getting values. They work ok for just variables but how can I use them for tables?
The module:
local knit = require(game.ReplicatedStorage.Packages.Knit)
module = knit.CreateService({
Name = "PlayerDataManager",
Client = {callbackRE = knit.CreateSignal()}
})
module.Profiles = {}
local settingCallbacks = {}
function module:CheckData(plr:Player)
if module.Profiles[plr.UserId] then
return true
else
return false
end
end
function module:Get(plr:Player)
local profile = module.Profiles[plr.UserId]
if not profile then
return
end
return profile.Data
end
function module:Set(plr,settingn,value)
local setting = tostring(settingn).upper(settingn)
local profile = module.Profiles[plr.UserId]
if not profile then
return
end
profile.Data[setting] = value
module.Client.callbackRE:Fire(plr,setting,value)
if settingCallbacks[setting] then
for _, callback in ipairs(settingCallbacks[setting]) do
callback(plr, setting)
end
end
end
function module:registerCallback(plr, setting, callback)
local settingName = tostring(setting).upper(setting)
print(plr,settingName,callback)
if not settingCallbacks[settingName] then
settingCallbacks[settingName] = {}
end
table.insert(settingCallbacks[settingName], callback)
end
for k,func in pairs(module) do
module.Client[k] = k ~= "Set" and func
end
return module
And the template:
local module = {
FOV = 100,
MUSIC = true,
LEVELS = 1, --how many levels has the player unlocked
BEST_TIMES = {}; --lowest times the player has completed the level (for speedrunning)
}
return module
Note that any suggestion would help!