How should i use metatable to prevent missing data?

Hey there, just wanted to know how i can proceed metatable for this kind of systems so in case of missing data it just straight up return a fresh and new table without a lot of useless if checks.

However im encountering nil as print. How should i resolve this?
image

-- Services
local DataStoreService = game:GetService("DataStoreService")
local PlayersS = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Reco the datastore
local BankDataStore = DataStoreService:GetDataStore("UserBank")

local GeneralData = {
	__index = function(GeneralData,index)
		warn("GeneralData: "..tostring(index).." is not a valid member of GeneralData")
		
		return {
			DaillyClaimLimit = 500000,
			
		}
	end,
}

setmetatable(GeneralData,{})

PlayersS.PlayerAdded:Connect(function(player)
	print(GeneralData[player.UserId])
end)

The issue is this line here:

setmetatable(GeneralData,{})

It’s causing the metatable to not have the __index behaviour that you defined earlier.
Changing the line to be

setmetatable(GeneralData, GeneralData)

should fix it!

Thanks for the help, this indeed work!