What’s up fellow developers/scripters! So I lately have been thinking of a cool idea, to make a chatbot that chats out things from user input. I’ve got the game done, but I do not want to publish it for the sole reason: when a user puts in a swear word into the chatbot, it does not tag the words, so a user can go and make the bot swear damaging my reputation from ROBLOX and possibly banning me for this. That explains why this topic is made. I do not know how to implement the ROBLOX chat filter into my chatbot to prevent it from saying swear words, and I’d be disappointed if after all the project is a no-go. I have tried searching on the Developer Hub. I did find a topic quite related to filtering of the chat, but I can’t seem to find out how to make this do anything but anything on my game. So that’s why I’m here.
This part of the script is what actually filters text:
local TextService = game:GetService("TextService")
local function getTextObject(message, fromPlayerId)
local textObject
local success, errorMessage = pcall(function()
textObject = TextService:FilterStringAsync(message, fromPlayerId)
end)
if success then
return textObject
end
return false
end
local function getFilteredMessage(textObject, toPlayerId)
local filteredMessage
local success, errorMessage = pcall(function()
filteredMessage = textObject:GetChatForUserAsync(toPlayerId)
end)
if success then
return filteredMessage
end
return false
end
I’ve used this code a while ago for a messaging system I made. I basically pasted this in a server script and I did this:
local textToBeFiltered = "gimme ur robux"
local playerThatSent = game.Players.evilguy
local playerThatRecieves = game.Players.goodboi
local textObject = getTextObject(textToBeFiltered, playerThatSent.UserId)
local filteredResult = getFilteredMessage(textObject, playerThatRecieves.UserId)
-- filteredResult variable is now the filtered string version of the original message