I have a script that is activated by a screen gui you input the text and then click a button and then it will change the text of a surface gui how do i add a chat filter too it? Uses a remote event btw.
ClickButton Script (Local)
local event = game.ReplicatedStorage.message -- Remote Event Location function click() local mess = script.Parent.Parent.TextBox -- Removed the .Text event:FireServer("ChangeText",mess.Text) -- Text and argument send here to server. script.Parent.Parent.TextBox.Text = "" end script.Parent.MouseButton1Click:Connect(click)
Server Script (non-local)
local event = game.ReplicatedStorage.message -- Remote Event Location event.OnServerEvent:Connect(function(player,arg,text) -- On fire event if arg == "ChangeText" then -- Check for argument -- Change Text workspace.Message.SurfaceGui.Frame.words.Text = tostring(text) wait(5) workspace.Message.SurfaceGui.Frame.words.Text = "" end end) local ReplicatedStorage = game:GetService("ReplicatedStorage") local TextService = game:GetService("TextService") local sendMessageEvent = ReplicatedStorage.SendPrivateMessage local function getTextObject(message, fromPlayerId) local textObject local success, errorMessage = pcall(function() textObject = TextService:FilterStringAsync(message, fromPlayerId) end) if success then return textObject end return false end local function getFilteredMessage(textObject, toPlayerId) local filteredMessage local success, errorMessage = pcall(function() filteredMessage = textObject:GetChatForUserAsync(toPlayerId) end) if success then return filteredMessage end return false end -- Called when client sends a message local function onSendMessage(sender, recipient, message) if message ~= "" then -- Filter the incoming message and send the filtered message local messageObject = getTextObject(message, sender.UserId) if messageObject then local filteredMessage = getFilteredMessage(messageObject, recipient.UserId) sendMessageEvent:FireClient(recipient, sender, message) end end end sendMessageEvent.OnServerEvent:Connect(onSendMessage)