FILTERED TEXT ERRORS: Returning error: string expected, got nil. Also, print: "TextFilterResult" instead of the filtered text. HELP!

I am
trying to filter texts to make posts.

SERVER

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local MessagingService = game:GetService("MessagingService")
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local HttpsService = game:GetService("HttpService")
local DatastoreServive = game:GetService("DataStoreService")
local TextService = game:GetService("TextService")

--// Datasores
local Data_TotalAmount = DatastoreServive:GetDataStore("TotalAmountOfPosts")

--// Objects
local Events = ReplicatedStorage:WaitForChild("Events")
local TotalVal = Instance.new("IntValue")

--// Events
local SendPost = Events:WaitForChild("SendPost")
local ChangeData = Events:WaitForChild("ChangeData")
local ClientToServer = Events:WaitForChild("SendFilterSignalToServer")
local ServerToClient = Events:WaitForChild("SendFilterSignalToClient")

--// Code

TotalVal.Value = 0

ClientToServer.OnServerEvent:Connect(function(Player, T, M)
    local filtertedText = ""
    local filteredMessage = ""
    local success, errorMessage = pcall(function()
        filtertedText = TextService:FilterStringAsync(T, Player.UserId)
        print(tostring(filtertedText))
    end)
    if not success then
        print(errorMessage)
    end
    
    local success2, errorMessage2 = pcall(function()
        filteredMessage = TextService:FilterStringAsync(M, Player.UserId)
        ServerToClient:FireClient(Player, filteredMessage, filtertedText)
        print(filteredMessage)
    end)
    if not success2 then
        print(errorMessage)
        return
    end
    
    if success and success2 then
        ServerToClient:FireClient(Player)
    end
end)

MessagingService:SubscribeAsync("SendPost", function(messages)
    messages = messages.Data
    print(messages[1])
    print(messages[2])
    print(messages[3])
    print(messages[4])
    TotalVal.Value = TotalVal.Value +1
    for _, player in pairs(Players:GetPlayers()) do
        if player.PlayerGui.MainGui.MainFrame["Newest Posts"] then
            local ClonedPost = player.PlayerGui.MainGui.MainFrame["Newest Posts"].Template
            ClonedPost.Parent = player.PlayerGui.MainGui.MainFrame["Newest Posts"]
            ClonedPost.Username.Text = "@"..messages[1]
            ClonedPost.DisplayName.Text = messages[2]
            ClonedPost.Message.Text = messages[4]
            ClonedPost.Title.Text = messages[3]
            local unique = HttpsService:GenerateGUID(false)
            ClonedPost.UniquePostNumber.Text = unique
            
            local userId = player.UserId
            local thumbType = Enum.ThumbnailType.HeadShot
            local thumbSize = Enum.ThumbnailSize.Size100x100
            local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
            
            local ProfilePic = ClonedPost.ProfilePicture
            
            ProfilePic.Image = content

            
            ------------------------------
            local success, errorMessage = pcall(function()
            Data_TotalAmount:SetAsync("Key", TotalVal.Value)
            end)
            if not success then
                print(errorMessage)
            end
        end
            ------------------------------
        
        TotalVal.Value = TotalVal.Value +1
        Data_TotalAmount:SetAsync("Key", TotalVal.Value)
    end
end)

SendPost.OnServerEvent:Connect(function(Player:Player, A:TextBox, B)
    MessagingService:PublishAsync("SendPost", {Player.Name, Player.DisplayName, Player.MessageString.Value, Player.TitleString.Value})
    print(Player.Name)
    print(Player.DisplayName)
end)

ChangeData.OnServerEvent:Connect(function(Player, T, M)
    Player:WaitForChild("MessageString").Value = M
    Player.TitleString.Value = T
    warn("Running V1 Of Change Data")
end)

local ds = game:GetService("DataStoreService"):GetDataStore("GlobalValue")
local SERVER_KEY_NAME = "Server"

local success, data = pcall(function()
    return ds:GetAsync(SERVER_KEY_NAME)
end)


ds:SetAsync(SERVER_KEY_NAME, TotalVal.Value)

wait(4)

if success then
    print(data) -->> the server data
    for i, v in pairs(Players:GetPlayers()) do
        v.PlayerGui.MainGui.MainFrame.TotalAmount.Text = "Total Amount Of Posts: "..tostring(data) 
    end
end

game.Players.PlayerAdded:Connect(function(plr)
    plr.PlayerGui.MainGui.MainFrame.TotalAmount.Text = "Total Amount Of Posts: "tostring(data)
end)

TotalVal:GetPropertyChangedSignal("Value"):Connect(function()
    TotalVal.Value = TotalVal.Value -1
    ds:SetAsync(SERVER_KEY_NAME, TotalVal.Value)
    wait(4)
    for i, v in pairs(Players:GetPlayers()) do
    v.PlayerGui.MainGui.MainFrame.TotalAmount.Text = "Total Amount Of Posts: "..tostring(TotalVal.Value)
    end        
end)

CLIENT

local vNumber = "1.1"
local OkToPost = false

warn("Running version "..vNumber.." for RoFeed. Current game name for refrence: "..game.Name..". DevKeia's property!")

--// Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Events = ReplicatedStorage:WaitForChild("Events")
local TweenService = game:GetService("TweenService")
local TextService = game:GetService("TextService")

local InfoTween = TweenInfo.new(0.7, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out)

--// Events
local SendPost = Events:WaitForChild("SendPost")
local ChangeData = Events:WaitForChild("ChangeData")
local SendSignalToServerPost = Events:WaitForChild("SendFilterSignalToServer")
local SendFilterSignalToClient = Events:WaitForChild("SendFilterSignalToClient")

--// Objects
local MainGui = script.Parent
local MainFrame = MainGui:WaitForChild("MainFrame")
local NotificationFrame = script.Parent.Notification

local PostTitle = MainFrame:WaitForChild("PostTitle")
local PostMessage = MainFrame:WaitForChild("PostMessage")
local PostButton = MainFrame:WaitForChild("PostButton")

local LoadingFrame = script.Parent.Loading
local LoadingNotice = LoadingFrame:WaitForChild("Notice")

LoadingFrame.Visible = true

task.wait(0.5)
LoadingNotice.Text = "Sending Data!"
task.wait(0.5)
LoadingNotice.Text = "Gathering your posts!"
task.wait(1)
LoadingNotice.Text = "Checking the feeds."
task.wait(0.5)
LoadingNotice.Text = "Sending 'Messaging Service' signal!"
task.wait(0.5)
LoadingNotice.Text = "Checking for ReplicatedStorage events..."
task.wait(1)
LoadingNotice.Text = "Loading GUI..."
task.wait(0.5)
LoadingNotice.Text = "Done!"

LoadingFrame:TweenPosition(UDim2.new(0, 0,0, 850))

--// Code

SendFilterSignalToClient.OnClientEvent:Connect(function(M, T)
    OkToPost = true
    PostMessage.Text = M
    PostTitle.Text = T
end)

PostButton.MouseButton1Click:Connect(function()
    if PostTitle.Text ~= "TITLE:" then
        if PostMessage.Text ~= "WHAT DO YOU WANT TO TELL THE WORLD?" then
            SendSignalToServerPost:FireServer(PostTitle.Text, PostMessage.Text)
            wait(0.2)
            SendFilterSignalToClient.OnClientEvent:Connect(function()
                OkToPost = true
            end)
            wait(0.1)
            if OkToPost == true then
            NotificationFrame.Visible = true
            NotificationFrame.Note.Text = "Sending your data to the server..."
            ChangeData:FireServer(PostMessage.Text, PostTitle.Text)
            wait(0.3)
            NotificationFrame.Note.Text = "Sending the post along all servers..."
            SendPost:FireServer(PostTitle.Text, PostMessage.Text)
            NotificationFrame.Note.Text = "Posting..."
            wait(0.3)
            NotificationFrame.Note.Text = "Done!"
            wait(0.3)
            NotificationFrame.Note.Text = "Adding your post to current Datastore."
            wait(1.5)
            NotificationFrame.Visible = false
                warn("Sucessfully ran V1 of Publishing Messaging Service for RoFeed")
            elseif OkToPost == false then
                NotificationFrame.Note.Text = "Your post couldn't be filtered. Please only post appropriate posts!"
                wait(1.5)
                NotificationFrame.Visible = false
            end
        end
    end
end)

EVERYTHING WORKED BEFORE ADDING THE TEXT FILTERING IN.

filtertextasync returns a filter result instance. Read the docs :100:

ok how would i get the text that is filtered. sorry i am new lol

could you quickly go into a team test or in game and see if it works? I’m too lazy to read lmao (jk)

According to the documentation, you have done it correctly. I’m not quite sure what could be erroring here.

ill give u a file. please use for the good.

1 Like

also u need to publish the game for it to work, again please dont sell or uncopylock this.

wait. you don’t need to send me the entire game

I can try and replicate it in my own studio game

no need!

ok, thanks! that would be great.

1 Like

it might take a while… there is a lot of UI things going on here that I have to spoof

fr just let me send u a file. ill message u

I just sent it to you! No spoofing needed.

I mean thanks…?

please don’t do this regularly

You did spell ‘filteredText’ wrong, but that doesn’t really affect the script since you spelt it wrong in all areas of the script.

Also, the variable print(errorMessage) should be errorMessage2 after the second filtering function. Just a little typo you made there assuming since you just copied and pasted from the previous.

None of these issues should affect the functionality of the script, but to confirm, you’re getting no errors? If you aren’t, you should try testing this in-game as STUDIO DOES NOT FILTER TEXT in play test mode.

ALSO. You aren’t sending any variables when you fire the client from the server, but on the client side I can see there are required variables?

image

image

Use game:GetService(“Chat”) instead of TextService. The reason being that Chat’s “FilterStringAsync” function will return the filtered string immediately instead of an instance like how TextService’s function works.

1 Like

I figured it out. TYSM! I really appreciate it.

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