Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[Solved]: How do I Add String Filtering Function in my Script?

Asked by 2 years ago
Edited 2 years ago

Hello my kind scripters,

I had a simple chat script in ServerScriptService. I made it so that client sent a message through text box and the Server-Sided script would receive it and send it back to all clients. The script in ServerScriptService also adds cool feature like; System messages, Devs and Owner messages etc. I need help setting a Message filtering function to tag inappropriate messages in the Server-Sided script

The Local Script

01local serverMessageColor = Color3.fromRGB(255, 255, 0)
02local Event = game.ReplicatedStorage.ServerMessageSystem
03local SentBack = game.ReplicatedStorage.BackToClient
04--==================================================
05-- sends message from textbox when pressed Enter
06script.Parent.FocusLost:Connect(function(Enter)
07 
08    if Enter then
09        Event:FireServer(script.Parent.Text)
10    end
11    script.Parent.Text = ""
12end)
13--==========================
14-- adds messages to scrolling frame and deletes oldest one when there are 17 messages
15function Newlabel(text,bool,color)
View all 39 lines...

The local script above gets the message in text box and sends the name and message to the script in ServerScriptService by remote events. It also receives the messages through remote events from the script in ServerScriptService back to the client and adds a new text label with the name and message and also colors the System messages.

The Script in ServerScriptService

01local Event = game.ReplicatedStorage.ServerMessageSystem
02local SendAllEvent = game.ReplicatedStorage.BackToClient
03local DevTextMessageColor = Color3.fromRGB(255, 0, 0)
04local NormalMessageColor = Color3.fromRGB(255, 255, 255)
05local color
06local text2
07--=========================================
08-- if the name is in devs it makes devs specific message
09function NewMessageDisplay(player, text)
10    if player.Name == "ABDULGHANI1010" or player.Name == "ImAGoodBoy12317" then
11        color = DevTextMessageColor
12        text2 = "[Dev]["..player.Name.."]: "..text
13    else
14if name is not in devs then makes a normal message
15        color = NormalMessageColor
View all 34 lines...

The server Script sends the message received from a client and sends it back to all clients. It also creates custom messages for the admins of the game. I need help with filtering the messages sent from the client to the server script. I want to add the function in the Server-Sided script. If I don't filter the message my game might get moderated. I am providing extra data so I can receive replies as soon as possible.

feel free to ask questions.

Your Average Roblox scripter,

ABDULGHANI1010

1 answer

Log in to vote
0
Answered by
Miniller 562 Moderation Voter
2 years ago
Edited 2 years ago

Read this article about text and chat filtering efficiently.

First you will have to use TextService:FilterStringAsync(message, fromPlayerID) to get an Instance of TextFilterResult.

You will then use textObject:GetNonChatStringForBroadcastAsync() to get the actual filtered string. (You could also use GetNonChatStringForUserAsync and GetChatForUserAsync for other purposes)

01local TextService = game:GetService("TextService")
02 
03local function getTextObject(message, fromPlayerId)
04    local textObject
05    local success, errorMessage = pcall(function()
06        textObject = TextService:FilterStringAsync(message, fromPlayerId)
07    end)
08    if success then
09        return textObject
10    end
11    return false
12end
13 
14local function getFilteredMessage(textObject)
15    local filteredMessage
View all 44 lines...

Please note that this isn't the most efficient solution, when sending the same message multiple times the TextFilterResult will always be the exact same.

1
Thank you so much for the Help "Miniller" . It helped so much. We need more people like you and have a good Day/Night Hi_People1133 218 — 2y
Ad

Answer this question