I’m sorry if this title is confusing, but i have no idea on how to call this problem, it honestly is hard for me to describe, so please look for yourself…
I want to achieve that if you put a text into a textbox and you press enter, that it will go through filtering and gets sent back as the filtered version and creates a chat system message with the filtered string
localscript:
local TextBox = script.Parent
local Button = script.Parent.Parent.TextButton
local localplayer = game:GetService("Players").LocalPlayer
local FilterEvent = game:GetService("ReplicatedStorage").Events:WaitForChild("FilterEvent")
local function SendMessage(message)
warn("Message sent")
game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage",{
Text = "["..localplayer.Name.."]: ".. message,
Color = Color3.fromRGB(150, 177, 255)
})
end
FilterEvent.OnClientEvent:Connect(function(Player,message,forwhat)
if forwhat == "Custom chat" then
warn("Fired from the server")
return SendMessage(message)
end
end)
TextBox.FocusLost:connect(function(enterPressed)
if enterPressed then
warn("Server fired")
FilterEvent:FireServer(script.Parent.Text,"Custom chat")
end
end)
Script:
local TxtService = game:GetService("TextService")
local FilterEvent = game:GetService("ReplicatedStorage").Events:WaitForChild("FilterEvent")
game.Players.PlayerAdded:Connect(function(Player)
FilterEvent.OnServerEvent:Connect(function(filterMessage,forwhat)
warn("Fired from client")
if forwhat == "Custom chat" then
warn("Got past forwhat")
local message
local success,errorMessage = pcall(function()
message = TxtService:FilterStringAsync(filterMessage,Player.UserId)
warn("Filtering...")
end)
if success then
FilterEvent:FireAllClients(Player,message,"Custom chat")
warn("Client fired".." ... ".."Filtering successful")
else
warn("Error while filtering "..filterMessage.." Error: "..errorMessage)
end
end
end)
end)