--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...
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)