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

My chat GUI wont use the chat filtered message?

Asked by 4 years ago
--Made by Jeysea
local event = game:GetService('ReplicatedStorage'):WaitForChild('Chatted')
local TextService = game:GetService('TextService')
event.OnServerEvent:connect(function(player, nameColor, message, messageColor)
local TextService = game:GetService("TextService")
local filteredTextResult = TextService:FilterStringAsync(player, player.Id)

  local filteredText = ""
local success, errorMessage = pcall(function()
    filteredTextResult = TextService:FilterStringAsync(message, player.Id)
end)
if not success then

    -- Put code here to handle filter failure
end
event:FireAllClients(player, nameColor, message, messageColor)
end)

How do I fix this code? This is getting me on confusion and I really can't find a way to fix this...

1 answer

Log in to vote
0
Answered by
IDKBlox 349 Moderation Voter
4 years ago

You have yourself a couple of issues 1. Id is not a valid property of the player, try UserId 2. You're just sending the regular message, you're not even attempting to send the filtered message.

Give this a shot. Read over it and look at what i've done... Try to learn from this.

if you have any questions, feel free to ask!

local event = game:GetService('ReplicatedStorage'):WaitForChild('Chatted')
local TextService = game:GetService('TextService')

local function filterMessage(player,message,sendAnyways)
    local success, result = pcall(TextService.FilterStringAsync, TextService, message, player.UserId)
    if success then
         local filteredMessage = result:GetNonChatStringForBroadcastAsync()
        if string.sub(filteredMessage,1,1) == '#' and sendAnyways == false then
            return false,'Message got filtered'
        end
        return true,nil, filteredMessage
    else
        -- error
    end
end

event.OnServerEvent:Connect(function(player, nameColor,message, messageColor)
    local success,errorMessage,filteredMessage = filterMessage(player,message,false) -- Set to true if you want the message to send if it filters ####### (Basically it'll send Pound signs')
    if success then
        event:FireAllClients(player,nameColor,filteredMessage,messageColor)
    else
        print('Filtered issue was:',errorMessage,'  So message was NOT sent')
    end
end)
0
Wow... Why did you had to write it...? Thank you so much and for the helps... Didn't know someone would help me this much... God bless you man... TinfoilbotGamer 35 — 4y
0
Did you have a question? That's why I had to write it. If i'm able to help. I want it to be a good answer.I am a visual learner and I know how I am when I need help. So may as well show people what to do and have them learn from it :). But you're welcome! Plus doing examples like this; I learn too! so it's a win win! IDKBlox 349 — 4y
Ad

Answer this question