[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
01 | local serverMessageColor = Color 3. fromRGB( 255 , 255 , 0 ) |
02 | local Event = game.ReplicatedStorage.ServerMessageSystem |
03 | local SentBack = game.ReplicatedStorage.BackToClient |
06 | script.Parent.FocusLost:Connect( function (Enter) |
09 | Event:FireServer(script.Parent.Text) |
11 | script.Parent.Text = "" |
15 | function Newlabel(text,bool,color) |
17 | local MessageNew = game.ReplicatedStorage.NewMessage:Clone() |
18 | MessageNew.Text = text |
19 | MessageNew.TextColor 3 = color |
20 | MessageNew.Parent = script.Parent.Parent.ScrollingFrame |
21 | if #script.Parent.Parent.ScrollingFrame:GetChildren() > = 17 then |
22 | for i,v in pairs (script.Parent.Parent.ScrollingFrame:GetChildren()) do |
23 | if v.Name ~ = "LocalScript" and v.Name ~ = "UIListLayout" and i = = 3 then |
30 | elseif bool = = true then |
31 | local MessageNew = game.ReplicatedStorage.NewMessage:Clone() |
32 | MessageNew.Text = text |
33 | MessageNew.Parent = script.Parent.Parent.ScrollingFrame |
34 | MessageNew.TextColor 3 = serverMessageColor |
39 | SentBack.OnClientEvent:Connect(Newlabel) |
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
01 | local Event = game.ReplicatedStorage.ServerMessageSystem |
02 | local SendAllEvent = game.ReplicatedStorage.BackToClient |
03 | local DevTextMessageColor = Color 3. fromRGB( 255 , 0 , 0 ) |
04 | local NormalMessageColor = Color 3. fromRGB( 255 , 255 , 255 ) |
09 | function NewMessageDisplay(player, text) |
10 | if player.Name = = "ABDULGHANI1010" or player.Name = = "ImAGoodBoy12317" then |
11 | color = DevTextMessageColor |
12 | text 2 = "[Dev][" ..player.Name.. "]: " ..text |
14 | if name is not in devs then makes a normal message |
15 | color = NormalMessageColor |
16 | text 2 = "[" ..player.Name.. "]: " ..text |
19 | SendAllEvent:FireAllClients(text 2 , false ,color) |
23 | game.Players.PlayerAdded:Connect( function (plr) |
24 | local textsend = "[System]: " ..plr.Name.. " has joined the game!" |
25 | SendAllEvent:FireAllClients(textsend, true ) |
29 | game.Players.ChildRemoved:Connect( function (plr) |
30 | local textsend = "[System]: " ..plr.Name.. " has left the game!" |
31 | SendAllEvent:FireAllClients(textsend, true ) |
34 | Event.OnServerEvent:Connect(NewMessageDisplay) |
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