Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is this text filtering script adequate enough?

Asked by
2ndwann 131
4 years ago
Edited 4 years ago

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.

0
The client shouldn't be deciding what should be filtered (otherwise the game will not be propertly filtered, as a hacker can just call the remote which sets the sign's text directly without filtering it) by calling a remote; you should instead filter the text when the client fires the sign text change remote. hiimgoodpack 2009 — 4y

Answer this question