I came across this issue a long time ago and I had sort of just made a band aid solution to it by writing a bunch of if statements and told myself ill come back to it when i become a more compotent scripter. But clearly im not compotent enough because i still dont know how to do this. Im using profile service and im creating a set data function which takes in any number of arguements as the index keys. heres the code if you want to take a look.
function PlayerData:Set(Player, Value,...)
local Profile = GetProfile(Player)
local IndexKeys = {...}
if IndexKeys[1] and Profile.Data[IndexKeys[1]] then
if IndexKeys[2] and Profile.Data[IndexKeys[1]][IndexKeys[2]] then
if IndexKeys[3] and Profile.Data[IndexKeys[1]][IndexKeys[2]][IndexKeys[3]] then
if IndexKeys[4] and Profile.Data[IndexKeys[1]][IndexKeys[2]][IndexKeys[3]][IndexKeys[4]] then
if type(Value) == type(Profile.Data[IndexKeys[1]][IndexKeys[2]][IndexKeys[3]][IndexKeys[4]]) then
Profile.Data[IndexKeys[1]][IndexKeys[2]][IndexKeys[3]][IndexKeys[4]] = Value
else
warn("Value types did not match;".. tostring(type(Value)).. " ".. tostring(type(Profile.Data[IndexKeys[1]][IndexKeys[2]][IndexKeys[3]][IndexKeys[4]])))
end
else
if type(Value) == type(Profile.Data[IndexKeys[1]][IndexKeys[2]][IndexKeys[3]]) then
Profile.Data[IndexKeys[1]][IndexKeys[2]][IndexKeys[3]] = Value
else
warn("Value types did not match;".. tostring(type(Value)).. " ".. tostring(type(Profile.Data[IndexKeys[1]][IndexKeys[2]][IndexKeys[3]])))
end
end
else
if type(Value) == type(Profile.Data[IndexKeys[1]][IndexKeys[2]]) then
Profile.Data[IndexKeys[1]][IndexKeys[2]] = Value
else
warn("Value types did not match;".. tostring(type(Value)).. ", ".. tostring(type(Profile.Data[IndexKeys[1]][IndexKeys[2]])))
end
end
else
if type(Value) == type(Profile.Data[IndexKeys[1]]) then
Profile.Data[IndexKeys[1]] = Value
else
warn("Value types did not match;".. tostring(type(Value)).. ", ".. tostring(type(Profile.Data[IndexKeys[1]])))
end
end
else
warn("No indices given")
end
end