I am making a script that filters the text for a sign. I am wondering if the script will function the same for other players in the server.
Note: I made use of the GetNonChatStringForBroadcastAsync()
function to decipher the TextFilterResult
.
Here is the server script below:
-- Script local TextService = game:GetService("TextService") local event = game:GetService("ReplicatedStorage"):WaitForChild("ChatFilterEvent") -- Get the TextFilterResult local function getTextObject(message, fromPlayerId) local textObject local success, errorMessage = pcall(function() textObject = TextService:FilterStringAsync(message, fromPlayerId) end) if success then return textObject -- Return the TextFilterResult elseif errorMessage then print("Error generating TextFilterResult:", errorMessage) -- Error message end return false end -- Turn the TextFilterResult into a string in plain English local function getFilteredMessage(textObject) local filteredMessage local success, errorMessage = pcall(function() filteredMessage = textObject:GetNonChatStringForBroadcastAsync() end) if success then return filteredMessage -- Return the filtered message in plain English elseif errorMessage then print("Error filtering message:", errorMessage) -- Error message end return false end -- Filter the incoming message and send the filtered message local function filter(player, text) if text ~= "" then local messageObject = getTextObject(text, player.UserId) -- Turn the unfiltered message into a TextFilterResult local filteredText = "" filteredText = getFilteredMessage(messageObject) -- Turn the TextFilterResult into plain English print(filteredText) return filteredText -- Return the filtered text end end event.OnServerInvoke = filter -- When the event invokes, trigger the filter() function
I would appreciate any answers or corrections to this.