I will be honest, I was looking at your other PorfileService post that you marked as solved. It wasn’t solved. Bracketing keys in tables is only required when you have a space inside the key. ["Island Name"] where “IslandName” is fine.
The problem you are having is you are sending Slot1["Difficulty] as an argument. You are basically telling the script to use the Value of Slot1[Difficulty] rather than the Path through the table. Changing this will cause other issues as you update your code correctly.
I do use Profile Service as well, and have for a long time, this is how I handle most of my Get/Set functions for my profile.Data, do note sometimes I use situational one-offs.
Rather than completely change your code for you, as you’re probably going to have to change a bit, let me provide my code that I use, and point you in the correct direction. If you have any other questions about what the code provided does, or want a better point of direction, feel free to DM me on the DevForums.
-- Loops through the given table ( I usually pass the entire profile.Data table)
-- and returns the given Value of Key (if found). Good for Profile:GetData() uses
local function TableSearchValue(SearchTable, SearchValue)
for Key, Value in pairs(SearchTable) do
if Key == SearchValue then
return Value
elseif type(Value) == "table" then
local result = TableSearchValue(Value, SearchValue)
if result then
return result
end
end
end
return nil
end
-- Loops through the given table ( I usually pass the entire profile.Data table)
-- and returns the path to be able to update. In your case, use such as:
-- local Path = TableSearchPath(profile.Data, "Difficulty") would return profile.Data.Slot1
-- where you then do Path["Difficulty"] = true (Updating your Difficulty value)
local function TableSearchPath(SearchTable, SearchValue, Path)
Path = Path or SearchTable
for Key, Value in pairs(SearchTable) do
local currentPath = Path
if Key == SearchValue then
return currentPath
elseif type(Value) == "table" then
local result = TableSearchPath(Value, SearchValue, currentPath[Key])
if result then
return result
end
end
end
return nil
end
-- Returns the given Value at Key
function ProfileModule:GetProfileData(player, DataName)
local profile = self.Profiles[player]
if DataName then
return TableSearchValue(profile.Data, DataName)
end
return self.Profiles[player]
end
-- Both :UpdateProfileData and :SetProfileData both change the values of DataName
-- to DataValue but I use them for different things, which is why there are two.
function ProfileModule:UpdateProfileData(player, DataName, DataValue)
local profile = self.Profiles[player]
if DataName and DataValue then
local profilePath = TableSearchPath(profile.Data, DataName)
if type(DataValue) == "number" then
profilePath[DataName] += DataValue
else
profilePath[DataName] = DataValue
end
end
if profile.Data.TrackerData["Total".. DataName] and DataValue > 0 then
self:UpdateProfileData(player, "Total".. DataName, DataValue)
end
self:CheckUpdate(player, DataName)
end
function ProfileModule:SetProfileData(player, DataName, DataValue)
local profile = self.Profiles[player]
if DataName and DataValue then
local profilePath = TableSearchPath(profile.Data, DataName)
profilePath[DataName] = DataValue
end
self:CheckUpdate(player, DataName)
end