Hello, and I have problem, Why does my third party chat filter only censor one bad word?
Here is my script:
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local HTTPService = game:GetService('HttpService')
local Chat = game:GetService('Chat')
local History = {}
game:GetService('Players').PlayerAdded:Connect(function(player)
wait(1)
ReplicatedStorage:WaitForChild('GetChatHistory'):FireClient(player, History)
end)
ReplicatedStorage:WaitForChild('Chat').OnServerEvent:Connect(function(player, text)
if text == '' then
else
local Url = 'https://api.sightengine.com/1.0/text/check.json?text='..text.."&mode=standard&lang=en&opt%5Fcountries=gb&api%5Fuser=xxxxxxx&api%5Fsecret=xxxxxxxxxx" -- make sure to url encode your api_secret and api_user
local RequestData = {
['request'] = {
["text"] = text,
["mode"] = 'standard',
['lang'] = 'en',
['opt_countries'] = 'gb',
['api_user'] = 'xxxxxxxx',
['api_secret'] = 'xxxxxxxxxx'
}
} -- we still use RequestData just in-case some properties are accessed from the post data.
local RequestData = HTTPService:JSONEncode(RequestData)
local ModeratedHTML = HTTPService:PostAsync(Url, RequestData)
local DecodedJSON = HTTPService:JSONDecode(ModeratedHTML)
local Filtered = text
print(DecodedJSON)
for _, profanity in pairs(DecodedJSON.profanity.matches) do
local swearword = string.sub(text, profanity.start+1, profanity['end']+1)
Filtered = string.gsub(text, swearword, string.rep('*', string.len(swearword)))
end
for _, personal in pairs(DecodedJSON.personal.matches) do
local swearword = string.sub(text, personal.start+1, personal['end']+1)
Filtered = string.gsub(text, swearword, string.rep('*', string.len(swearword)))
end
for _, link in pairs(DecodedJSON.link.matches) do
local swearword = string.sub(text, link.start+1, link['end']+1)
Filtered = string.gsub(text, swearword, string.rep('*', string.len(swearword)))
end
ReplicatedStorage.RecieveChat:FireAllClients('['.. player.DisplayName.. ']: '.. Filtered)
Chat:Chat(player.Character.Head, Filtered, Enum.ChatColor.White)
table.insert(History, '['.. player.DisplayName.. ']: '.. Filtered)
end
end)
So the chat filter doesn’t censor multiple bad words, The script only censors one bad word for some reason.