player.Chatted bypassed

I have a custom anti-toxicity filter for my game which uses player.Chatted, but exploiters are able to bypass it by using:

local str = tostring("text here")
game:GetService("ReplicatedStorage").DefaultChatSystemChatEvents.SayMessageRequest:FireServer(str, "All")

I am not sure how to patch this issue, so that’s why I have come to the DevForum for help.

My code:

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		-- anti-toxicity stuff here
	end)
end)

Also, this is my first topic, so correct me anywhere if I am wrong.

Can you show your “anti-toxicity stuff” code?

local HttpService = game:GetService("HttpService")

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(message)
		local msg = tostring(message)
		local score = HttpService:GetAsync("https://not-showing-you-the-url.com/?m=" .. msg)
		score = HttpService:JSONDecode(score).score

		if tonumber(score) < 0 then
			plr:Kick()
		end
	end)
end)

Then do something like this:

game:GetService("ReplicatedStorage"):WaitForChild("DefaultChatSystemChatEvents").SayMessageRequest.OnServerEvent:Connect(function(plr,mes,target)
    -- Loop through blacklisted words
    if blacklistedWordFound then
        plr:Kick("Stop exploiting.")
    end
end)

I’m pretty sure .Chatted accounts for when they send the event anyways, but I’m not sure. I hope this helps you!

It just gives this error:

You can simply check if that event is fired from server.

game:GetService("ReplicatedStorage"):WaitForChild("DefaultChatSystemChatEvents"):WaitForChild("SayMessageRequest").onServerEvent:Connect(function(player,message,channel)
  -- Your checking stuff
end)
Full code
local HttpService = game:GetService("HttpService")
game:GetService("ReplicatedStorage"):WaitForChild("DefaultChatSystemChatEvents"):WaitForChild("SayMessageRequest").onServerEvent:Connect(function(plr,message,channel)
	local msg = tostring(message)
	local score = HttpService:GetAsync("https://not-showing-you-the-url.com/?m=" .. msg)
	score = HttpService:JSONDecode(score).score

	if tonumber(score) < 0 then
		plr:Kick()
	end
end)
game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(message)
		local msg = tostring(message)
		local score = HttpService:GetAsync("https://not-showing-you-the-url.com/?m=" .. msg)
		score = HttpService:JSONDecode(score).score

		if tonumber(score) < 0 then
			plr:Kick()
		end
	end)
end)
ReplicatedStorage:WaitForChild("DefaultChatSystemChatEvents")

Sorry, try my code now (it didn’t wait for the event)