I have made a custom chat gui that sends messages but the one problem is that it’s not filtered, meaning you can swear without it getting censored. I have been looking at this post on the wiki (Text and Chat Filtering)
and I don’t know how to implement it into the scripts I have. If I could get some help on how to into the script that would be great!
Server Script
local event = game:GetService('ReplicatedStorage'):WaitForChild('Chatted')
event.OnServerEvent:connect(function(player, nameColor, message, messageColor)
event:FireAllClients(player, nameColor, message, messageColor)
end)
Local Script
local colors = {'Deep orange', 'Toothpaste', 'Lime green', 'Really red', 'Cyan', 'Gold'}
local TextService = game:GetService("TextService")
local player = game.Players.LocalPlayer
local nameColor = BrickColor.new(colors[math.random(1, #colors)]).Color
local messageColor = BrickColor.new('Institutional white').Color
local messageBox = script.Parent:WaitForChild('InputFrame'):FindFirstChild('MessageBox')
local UIS = game:GetService('UserInputService')
local event = game:GetService('ReplicatedStorage'):WaitForChild('Chatted')
function onInput(Input, GPE)
if GPE then return end
if Input.KeyCode == Enum.KeyCode.Slash then
messageBox:CaptureFocus()
end
end
function onFocus()
if messageBox.Text == 'Press \'/\' to type a message.' then
messageBox.Text = ''
end
end
function onFocusLost(EnterPressed)
if EnterPressed then
if messageBox.Text ~= '' then
event:FireServer(nameColor, messageBox.Text, messageColor)
messageBox.Text = 'Press \'/\' to type a message.'
else
messageBox.Text = 'Press \'/\' to type a message.'
end
else
if messageBox.Text == '' then
messageBox.Text = 'Press \'/\' to type a message.'
end
end
end
function addLine(message, Label)
local chatBox = script.Parent:FindFirstChild('Frame')
local newMessage = Instance.new('Frame', chatBox)
newMessage.Size = UDim2.new(1, -10, 0, 20)
newMessage.Position = UDim2.new(0, 5, 1, -25)
newMessage.BackgroundTransparency = 1
newMessage.ClipsDescendants = true
local lineMessage = ''
while Label.TextFits == false do
lineMessage = string.sub(message, -1) .. lineMessage
message = string.sub(message, 1, string.len(message) - 1)
Label.Text = message
end
for _, oldMessage in pairs (chatBox:GetChildren()) do
if oldMessage ~= newMessage then
oldMessage.Position = oldMessage.Position + UDim2.new(0, 0, 0, -newMessage.AbsoluteSize.Y + 5)
end
end
local messageLabel = Instance.new('TextLabel', newMessage)
messageLabel.BackgroundTransparency = 1
messageLabel.Font = 'SourceSansBold'
messageLabel.TextColor3 = messageColor
messageLabel.FontSize = 'Size18'
messageLabel.TextXAlignment = 'Left'
messageLabel.Text = lineMessage
messageLabel.Size = UDim2.new(1, -10, 0, 20)
messageLabel.TextStrokeTransparency = 0.6
messageLabel.Position = UDim2.new(0, 5, 0, 0)
local LineTag = Instance.new('StringValue', messageLabel.Parent)
LineTag.Name = 'LineTag'
local LineTag2 =Instance.new('StringValue', Label.Parent)
LineTag2.Name = 'LineTag'
if messageLabel.TextFits ~= true then
addLine(lineMessage, messageLabel)
print('addingling')
else
for _, oldMessage in pairs (chatBox:GetChildren()) do
if not oldMessage:FindFirstChild('LineTag') then
oldMessage.Position = oldMessage.Position + UDim2.new(0, 0, 0, -newMessage.AbsoluteSize.Y + 5)
end
end
end
LineTag:Destroy()
LineTag2:Destroy()
end
function onEvent(sender, nameColor, message, messageColor)
local chatBox = script.Parent:FindFirstChild('Frame')
local newMessage = Instance.new('Frame', chatBox)
newMessage.Size = UDim2.new(1, -10, 0, 20)
newMessage.Position = UDim2.new(0, 5, 1, -25)
newMessage.BackgroundTransparency = 1
newMessage.ClipsDescendants = true
local nameLabel = Instance.new('TextLabel', newMessage)
nameLabel.BackgroundTransparency = 1
nameLabel.Font = 'SourceSansBold'
nameLabel.TextColor3 = nameColor
nameLabel.FontSize = 'Size18'
nameLabel.TextXAlignment = 'Left'
nameLabel.Text = '[' .. sender.Name .. ']:'
nameLabel.Size = UDim2.new(0, nameLabel.TextBounds.X + 5, 0, 20)
nameLabel.TextStrokeTransparency = 0.6
local messageLabel = Instance.new('TextLabel', newMessage)
messageLabel.BackgroundTransparency = 1
messageLabel.Font = 'SourceSansBold'
messageLabel.TextColor3 = messageColor
messageLabel.FontSize = 'Size18'
messageLabel.TextXAlignment = 'Left'
messageLabel.Text = message
messageLabel.Size = UDim2.new(1, -nameLabel.AbsoluteSize.X, 0, 20)
messageLabel.Position = nameLabel.Position + UDim2.new(0, nameLabel.AbsoluteSize.X, 0, 0)
messageLabel.TextStrokeTransparency = 0.6
if messageLabel.TextFits ~= true then
addLine(message, messageLabel)
else
for _, oldMessage in pairs (chatBox:GetChildren()) do
if oldMessage ~= newMessage then
oldMessage.Position = oldMessage.Position + UDim2.new(0, 0, 0, -newMessage.AbsoluteSize.Y + 5)
end
end
end
end
UIS.InputBegan:connect(onInput)
event.OnClientEvent:connect(onEvent)
messageBox.Focused:connect(onFocus)
messageBox.FocusLost:connect(onFocusLost)