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
local serverMessageColor = Color3.fromRGB(255, 255, 0)
local Event = game.ReplicatedStorage.ServerMessageSystem
local SentBack = game.ReplicatedStorage.BackToClient
--==================================================
-- sends message from textbox when pressed Enter
script.Parent.FocusLost:Connect(function(Enter)
if Enter then
Event:FireServer(script.Parent.Text)
end
script.Parent.Text = ""
end)
--==========================
-- adds messages to scrolling frame and deletes oldest one when there are 17 messages
function Newlabel(text,bool,color)
if bool == false then
local MessageNew = game.ReplicatedStorage.NewMessage:Clone()
MessageNew.Text = text
MessageNew.TextColor3 = color
MessageNew.Parent = script.Parent.Parent.ScrollingFrame
if #script.Parent.Parent.ScrollingFrame:GetChildren() >= 17 then
for i,v in pairs (script.Parent.Parent.ScrollingFrame:GetChildren()) do
if v.Name ~= "LocalScript" and v.Name ~= "UIListLayout" and i == 3 then
v:Destroy()
end
end
end
--==========================
-- System message; color is yellow.
elseif bool == true then
local MessageNew = game.ReplicatedStorage.NewMessage:Clone()
MessageNew.Text = text
MessageNew.Parent = script.Parent.Parent.ScrollingFrame
MessageNew.TextColor3 = serverMessageColor
end
end
--======================================
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
local Event = game.ReplicatedStorage.ServerMessageSystem
local SendAllEvent = game.ReplicatedStorage.BackToClient
local DevTextMessageColor = Color3.fromRGB(255, 0, 0)
local NormalMessageColor = Color3.fromRGB(255, 255, 255)
local color
local text2
--=========================================
-- if the name is in devs it makes devs specific message
function NewMessageDisplay(player, text)
if player.Name == "ABDULGHANI1010" or player.Name == "ImAGoodBoy12317" then
color = DevTextMessageColor
text2 = "[Dev]["..player.Name.."]: "..text
else
if name is not in devs then makes a normal message
color = NormalMessageColor
text2 = "["..player.Name.."]: "..text
end
SendAllEvent:FireAllClients(text2,false,color)
end
--==================================
-- Sends a text that player has joined the game
game.Players.PlayerAdded:Connect(function(plr)
local textsend = "[System]: "..plr.Name.." has joined the game!"
SendAllEvent:FireAllClients(textsend,true)
end)
--===============================
-- sends message that player left the game
game.Players.ChildRemoved:Connect(function(plr)
local textsend = "[System]: "..plr.Name.." has left the game!"
SendAllEvent:FireAllClients(textsend,true)
end)
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

1 comment
Thank you so much for the Help "Miniller" . It helped so much. We need more people like you and have a good Day/Night