Am I using the __newindex parameters right?

I am creating this saving module that uses data store 2 for myself but whenever __newindex in called the Table parameter equals the table, the key parameter equals “Table”, and the value parameter equals a table. Am I using these parameters correctly?

module.CreateNewStore = function(plr)
	local leaderstatValues = {}
	
	
	
	
	local meta = setmetatable(leaderstatValues,{
		--[[__index = function(Table, key, value)
			local value = table.find(leaderstatValues, "BackUp") or table.insert(leaderstatValues, "BackUp")
			if plr:FindFirstChild(value) then
				if plr[value]:FindFirstChild(value) then
					return plr[value][value]
				end
			end
		end,--]]
		__newindex = function(table,key, value)
			module.DataStore.Combine(leaderstatValues[key] , plr)
			print(value[key])
			local valueStore = module.DataStore(value[key], plr)
			local function ValueUpdated(updatedValue)
				for _, instance in pairs(plr:GetChildren()) do
					if instance:IsA("Folder") then
						for _,globalValue in pairs(instance:GetChildren()) do
							if globalValue.Name == value then
								globalValue.Value = valueStore:Get(updatedValue)
							end
						end
					end
				end
			end
			ValueUpdated(0)
			valueStore:OnUpdate(ValueUpdated)
		end,
		
		
	})
	
	return meta
end

Here is my normal server script.

local LeaderstatsMod = require(game.ServerStorage.Modules.Leaderstats)
local EasySave = require(game.ServerStorage.Modules.EasySaveDataStore)



game.Players.PlayerAdded:Connect(function(plr)
	local MainStore = EasySave.CreateNewStore(plr)
	for Folder, Table in pairs(LeaderstatsMod.Folders) do
		local folder = Folder
		for Property, PropertyValue in pairs(Table) do
			folder[Property] = PropertyValue
			folder.Parent = plr
		end
	end
	for InstanceValue, Table in pairs(LeaderstatsMod.leaderstats) do
		local instance = InstanceValue
		for instanceProperty, InstancePropertyValue in pairs(Table) do
			if instanceProperty ~= "Parent" then
				print("Work")
				if instanceProperty == "Name" then
				MainStore[#MainStore + 1] = InstancePropertyValue
				end
			instance[instanceProperty] = InstancePropertyValue
			else
				instance.Parent = plr[InstancePropertyValue] or nil
				if not instance.Parent then
					plr:Kick('An error occured, sorry!')
				end
			end
		end
	end	
	MainStore:AddValue(plr.leaderstats.Wins, 10, plr)
end)

Thanks :smiley:

I think you should just stop using metatables entirely and instead create a handler function which saves the data into your array and handles the updating. Metatables are just going to make your code hard to follow.

Ok, but do you know why the value parameter is equal to a table?