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

Why is This Filter Script Only Returning "Instance"?

Asked by 6 years ago

I have a script to filter the text inputted by a player in a textbox.

Localscript

script.Parent.Parent.NameBox.FocusLost:connect(function(enterPressed)
   -- if enterPressed then
        if script.Parent.Parent.NameBox.Text ~= "" then
         filter:FireServer(game.Players.LocalPlayer, script.Parent.Parent.NameBox.Text)
        end
   -- end
end)

function onSwap(filteredtext)
    script.Parent.Parent.NameBox.Text = filteredtext
end

filter.OnClientEvent:Connect(onSwap)

Regular Script

local RS = game:GetService("ReplicatedStorage")
local filter = RS.Filter
local TextService = game:GetService("TextService")


local function getTextObject(message, fromPlayerId)
    local textObject
    local success, errorMessage = pcall(function()
        textObject = TextService:FilterStringAsync(message, fromPlayerId)
    end)
    if success then
        return textObject
    elseif errorMessage then
        print("Error generating TextFilterResult:", errorMessage)
    end
    return false
end

local function getFilteredMessage(textObject)
    local filteredMessage
    local success, errorMessage = pcall(function()
        filteredMessage = textObject:GetNonChatStringForBroadcastAsync()
    end)
    if success then
        return filteredMessage
    elseif errorMessage then
        print("Error filtering message:", errorMessage)
    end
    return false
end

function onSwtap(player, text)
    local messageObject = getTextObject(text, player.UserId)
    local filteredText = getFilteredMessage(messageObject)
    filter:FireClient(player, filteredText)
end

filter.OnServerEvent:Connect(onSwtap)

However, instead of returning a filtered name, it returns "Instance"

0
don’t know why, but filterstringasync actually returns an object(instance) brokenVectors 525 — 6y

1 answer

Log in to vote
1
Answered by
cabbler 1942 Moderation Voter
6 years ago

The problem is filter:FireServer(game.Players.LocalPlayer, script.Parent.Parent.NameBox.Text). OnServerEvent automatically gives you a player parameter, then your variant parameters will follow. So, you have accidentally given it a player instance instead of text.

Solution: filter:FireServer(script.Parent.Parent.NameBox.Text)

0
Thank you so much! I forgot about that. BouncingBrenda 44 — 6y
Ad

Answer this question