How do i break this loop?

Hello Developers,
i made this module but my problem is the function keeps repeating leading to an error ReplicatedStorage.ModuleScript:8: C stack overflow . The function was runned once by a server script but it runned multiple times or in loop.

-- Server
local filter = require(game.ReplicatedStorage.ModuleScript)
game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		filter:Chatted(player,msg)
	end)
end)
-- Module
local chat = {}
local metachat = {}
function metachat.__newindex(self,...)
	local arg = {...} 
	print(#arg)
	if not self[arg[1]] then
		print(arg[1])
		self[arg[1]] = {}
		table.insert(self[arg[1]], arg[2])
	else
		table.insert(self[arg[1]], arg[2])
	end
end
setmetatable(chat,metachat)
local filter = {}
function filter.Chatted(p,player,msg)
	metachat.__newindex(chat,player.Name,msg)
end
return filter

You aren’t supposed to use metatables/metamethods like this. You should be using it like

function filter.Chatted(p,player,msg)
	chat[player.Name] = msg --Fires the __newindex metamethod
end

sorry lol, i just add the meta because I’m trying to learn it. same as self function

I believe this is what’s causing it. You’re adding something to the self table, which fires __newindex, which runs the function, which adds something to the self table, over and over until it crashes.

and this