Text Filtering not working

Hi,

I’m implementing functionality into my game to filter text sent by the client, and for ease of use I’ve created the following function:

function GeneralUtils.FilterText(plr: Player, textToFilter: string, filterMethodToUse: "1" | "2" | "3"): { Text: string, Censored: boolean }
    local textFilterResult: TextFilterResult | nil = nil
    local success, errorMessage = pcall(function()
        textFilterResult = TextService:FilterStringAsync(textToFilter, plr.UserId)
    end)
    if not success then
        warn(`Error filtering text: {textToFilter}, :, {errorMessage}`)
        return { Text = "", Censored = false }
    end

    local stringToReturn = textToFilter

    local success2, errorMessage2 = pcall(function()
        if filterMethodToUse == "1" then
            print(textFilterResult:GetChatForUserAsync(plr.UserId))
            -- print(stringToReturn)
        elseif filterMethodToUse == "2" then
            print(textFilterResult:GetNonChatStringForBroadcastAsync())
            -- print(stringToReturn)
        elseif filterMethodToUse == "3" then
            print(textFilterResult:GetNonChatStringForUserAsync(plr.UserId))
            -- print(stringToReturn)
        else
            warn("Filter method not selected")
        end
    end)
    if not success2 then return { Text = "", Censored = false } end

    return {
        Text = stringToReturn,
        Censored = textToFilter ~= stringToReturn -- if they aren't equal, then the text was censored
    }
end

– called from another script

    print(GeneralUtils.FilterText(plr, name, "1"))
    print(GeneralUtils.FilterText(plr, name, "2"))
    print(GeneralUtils.FilterText(plr, name, "3"))

As seen above, I’ve tested it with all available TextFilterResult methods, however strings that should be censored aren’t. After rereading the documentation examples I haven’t found out where I’ve gone wrong.
Any help would be great thanks!

You might wanna see this topic:

The marked solution on this post doesn’t correctly use the filtering methods, and the documentation was also posted as a suggestion under this post which I’ve stated I’ve already read through.

Found my problem. Filtering text doesn’t work in studio. There was nothing wrong w my code, it’s just that testing it only works through the actual launcher. No clue why this is but it caused a good few hours of headaches

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.