First of all, it’s __index, not __Index. If I got it right, you wanna receive “No data!” if player doesn’t exist. The simple solution would be returning an empty inventory table where all slots are set to No Data, like this:
setmetatable(PlayerData, {
__index = function()
return {
Inventory = {
Primary = "No data!";
Secondary = "No data!"
}
}
end
})
However, if you’re planning on adding even more slots, you can set another metatable.
setmetatable(PlayerData, {
__index = function()
return {
Inventory = setmetatable({}, {__index = function()
return "No Data!"
end})
}
end
})
Though, if I were you, I wouldn’t overuse metatables for such purposes. They tend to be confusing at times and might even hurt performance.