What do you mean by “table combining system”, could you elaborate?
And has this error occured before?
What do you mean by “table combining system”, could you elaborate?
And has this error occured before?
I mean the code you sent that uses a directory to find a value
That’s weird, it shouldn’t be happening because the function isn’t automatically altering any of the profiles. Could you show me the script that you’re using to save your data?
local PlrDataHandler = {}
local Data = {
["PlayerStats"] = {
["Chakra"] = 0,
["Strength"] = 0,
["Health"] = 0,
},
["Levels"] = {
["Level"] = 1,
["Exp"] = 0,
["Points"] = 0,
}
}
local profileService = require(game.ServerScriptService.ProfileService)
local ProfileStore = profileService.GetProfileStore(
"PlayerProfile",
Data
)
local profiles = {}
function SearchTable(Table, directory)
local Int = 0;
while Int < #directory do
Table = Table[directory[Int + 1]];
Int += 1;
end;
print(table);
return Table;
end;
function RetrieveData(Player, directory)
local ReturnData = SearchTable(profiles[Player].Data, directory);
if ReturnData ~= nil then
return ReturnData;
else
warn("Data not found.");
return nil;
end;
end;
function PlayerAdded(plr)
local profile = ProfileStore:LoadProfileAsync("Player_"..plr.UserId)
if profile then
profile:AddUserId(plr.UserId)
profile:Reconcile()
profile:ListenToRelease(function()
profiles[plr] = nil
plr:Kick()
end)
if not plr:IsDescendantOf(game.Players) then
profile:Release()
else
profiles[plr] = profile
print(profiles[plr].Data)
end
print(profiles)
local function Capitalize(str)
str = string.gsub(str, "^%l", function(c) return string.upper(c) end)
return str
end
local function CheckTable(index,value, folder, FolderIndex)
if type(value) == "table" then
local obj = Instance.new("Folder")
if type(folder) == "string" then
obj.Parent = folder
else
obj.Parent = plr:FindFirstChild(FolderIndex, true)
end
obj.Name = index
for i, Val in pairs(value) do
CheckTable(i,Val, value, obj.Name)
end
else
local obj = Instance.new(Capitalize(type(value)).. "Value")
obj.Parent = plr:FindFirstChild(FolderIndex, true)
obj.Name = index
obj.Value = profiles[plr].Data[FolderIndex][index]
end
end
local DataFolder = Instance.new("Folder")
DataFolder.Parent = plr
DataFolder.Name = "Data"
for index, folder in pairs(Data) do
local obj = Instance.new("Folder")
obj.Parent = DataFolder
obj.Name = index
for i, Val in pairs(folder) do
CheckTable(i,Val, folder, index)
end
end
else
plr:Kick()
end
end
function PlrDataHandler:Init()
for _, plr in game.Players:GetPlayers() do
task.spawn(PlayerAdded, plr)
end
game.Players.PlayerAdded:Connect(PlayerAdded)
game.Players.PlayerRemoving:Connect(function(plr)
if profiles[plr] then
profiles[plr]:Release()
end
end)
end
function GetProfile(plr)
assert(profiles[plr], string.format("profile does not exist for %s", plr.UserId))
return(profiles[plr])
end
function PlrDataHandler:Get(player, directory, key)
local profile = GetProfile(player)
local RetrivedData = RetrieveData(player, directory)
assert(RetrivedData, string.format("Data does not exist for key %s", key))
return RetrivedData[key]
end
function PlrDataHandler:Set(player, key, value, directory)
local profile = GetProfile(player)
local RetrivedData = RetrieveData(player, directory)
assert(RetrivedData[key], string.format("Data does not exist for key %s", key))
assert(type(RetrivedData[key]) == type(value))
RetrivedData[key] = value
local valueOBJ = player:FindFirstChild(key, true)
if valueOBJ then
valueOBJ.Value = value
end
end
function PlrDataHandler:Update(player, key, callBack, directory)
local profile = GetProfile(player)
local oldData = self:Get(player, key, directory)
local newData = callBack(oldData)
self:Set(player, key, newData)
end
return PlrDataHandler
Try this:
local PlrDataHandler = {}
local DefaultProfile = {
["PlayerStats"] = {
["Chakra"] = 0,
["Strength"] = 0,
["Health"] = 0,
},
["Levels"] = {
["Level"] = 1,
["Exp"] = 0,
["Points"] = 0,
}
}
local Players = game:GetService("Players");
local ProfileService = require(game.ServerScriptService.ProfileService)
local ProfileStore = ProfileService.GetProfileStore(
"PlayerData",
DefaultProfile
)
local Profiles = {}
local function SearchTable(Table, directory)
local Int = 0;
while Int < #directory do
Table = Table[directory[Int + 1]];
Int += 1;
end;
return Table
end;
function OnLoaded(plr)
local function Capitalize(str)
str = string.gsub(str, "^%l", function(c) return string.upper(c) end)
return str
end
local function CheckTable(index,value, folder, FolderIndex)
if type(value) == "table" then
local obj = Instance.new("Folder")
if type(folder) == "string" then
obj.Parent = folder
else
obj.Parent = plr:FindFirstChild(FolderIndex, true)
end
obj.Name = index
for i, Val in pairs(value) do
CheckTable(i,Val, value, obj.Name)
end
else
local obj = Instance.new(Capitalize(type(value)).. "Value")
obj.Parent = plr:FindFirstChild(FolderIndex, true)
obj.Name = index
obj.Value = Profiles[plr].Data[FolderIndex][index]
end
end
local DataFolder = Instance.new("Folder")
DataFolder.Parent = plr
DataFolder.Name = "Data"
for index, folder in pairs(DefaultProfile) do
local obj = Instance.new("Folder")
obj.Parent = DataFolder
obj.Name = index
for i, Val in pairs(folder) do
CheckTable(i,Val, folder, index)
end
end
end
function PlayerAdded(plr)
local profile = ProfileStore:LoadProfileAsync("Player_" .. plr.UserId)
if profile ~= nil then
profile:AddUserId(plr.UserId)
profile:Reconcile()
profile:ListenToRelease(function()
Profiles[plr] = nil
plr:Kick()
end)
if plr:IsDescendantOf(Players) == true then
Profiles[plr] = profile
OnLoaded(plr)
else
profile:Release()
end
else
plr:Kick()
end
end
function PlrDataHandler:Init()
for _, plr in Players:GetPlayers() do
task.spawn(PlayerAdded, plr)
end
Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(function(plr)
if Profiles[plr] then
Profiles[plr]:Release()
end
end)
end
function GetProfile(plr)
assert(Profiles[plr], string.format("profile does not exist for %s", plr.UserId))
return(Profiles[plr])
end
function PlrDataHandler:RetrieveData(Player, directory)
local ReturnData = SearchTable(Profiles[Player].Data, directory);
if ReturnData ~= nil then
return ReturnData;
else
warn("Data not found.");
return nil;
end;
end;
function PlrDataHandler:Set(player, key, value, directory)
local profile = GetProfile(player)
local RetrivedData = PlrDataHandler:RetrieveData(player, directory)
RetrivedData = value
local valueOBJ = player:FindFirstChild(key, true)
if valueOBJ then
valueOBJ.Value = value
end
end
function PlrDataHandler:Update(player, key, callBack, directory)
local profile = GetProfile(player)
local oldData = PlrDataHandler:RetrieveData(player, directory)
local newData = callBack(oldData)
self:Set(player, key, newData)
end
return PlrDataHandler
Also, I highly suggest you clean your code up, because it’s pretty messy right now and has a lot of unnecessary stuff in it. To change your data you can just do:
local PlrDataHandler = require(script.PlrDataHandler)
PlrDataHandler:Init();
local Data = PlrDataHandler:RetrieveData(game:GetService("Players"):WaitForChild("Rixtys99"), {"PlayerStats"});
Data.Chakra += 1; -- Etc., if you only try to get one value, it'll not work so you have to get a table (in this case "PlayerStats")
Alright, I’ve never used ProfileService before so I just followed some posts to see how to do it, I’ll test it out and let you know
Unfortunately it still gives me the same error, I’m not sure why
Hmm, that’s weird because it worked fine for me. If you’re testing in studio check if you have Enable Studio Access to API Services
enabled. Also, you can check if your data was saved with this plugin. Moreover, you can check if you have the latest Profile Service version.