What do you want to achieve?
I want to detect if the player has chatted something that got censored.
So pretty much get the filtered message from Player.Chatted:Connect(function(msg).
What is the issue?
I have “no idea” on how to do this, I know that there is a function to filter the message, but I’m wondering if there is a more efficient way of doing this?
What solutions have you tried so far?
There are no examples online so I couldn’t try anything.
local plr = game:GetService("Players").LocalPlayer
plr.Chatted:Connect(function(msg)
--what am I suppose to do here???
end)
I am sure that you can still print their message even if it gets censored you can still see the message so you could use TextService to try and filter their message (which is just a string)
If it gets filtered that means their chat message and that way you’ll have it detected.
Don’t know how to do that? Here’s a community tutorial about this!
Just a claimer, filtering string doesn’t work in studio (if you didn’t know) so you’d need to publish the place and test it in the game instead of studio.
I followed the tutorial and I know it works because I used it once but now I’m getting some error called “Attemp to index boolean with ‘find’” which I understand but I dont understand why it is a boolean, I know that the script returns false if it fails but for this error to come everytime I filter a message means the Filter is simply broken.
local event = game:GetService("ReplicatedStorage"):WaitForChild("RE"):WaitForChild("Msg")
local TextService = game:GetService("TextService")
local function filterMessage(plr, msg)
local result
local success, err = pcall(function()
result = TextService:FilterStringAsync(msg, plr)
end)
if success then
return result
end
return false
end
local function getFilteredMessage(plr, msg)
local result
local success, err = pcall(function()
result = msg:GetChatForUserAsync(plr)
end)
if success then
return result
end
return false
end
event.OnServerEvent:Connect(function(plr, msg)
local filteredMessage = filterMessage(msg, plr.UserId)
local message = getFilteredMessage(filteredMessage, plr.UserId)
if message:find("#") then -- this is the error line btw
plr:Kick("You got censored.")
end
end)
Same error as the other script.
“Attemp to index boolean with ‘find’”
local event = game:GetService("ReplicatedStorage"):WaitForChild("RE"):WaitForChild("Msg")
event.OnServerEvent:Connect(function(plr, msg)
local message = game:GetService("Chat"):FilterStringForBroadcast(msg)
if message:find("#") then
plr:Kick("You got censored.")
end
end)
But this will only check the message before filtering, so it can’t detect the hashtags that might come after filtering.
(Sorry, I didn’t see the last part of your message.)
Alright, I tested it in-game and that seems to be true, so here’s the actual solution:
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
if game:GetService("Chat"):FilterStringForBroadcast(msg, plr):find("#") then
print("filtered")
end
end)
end)
TextService:FilterStringAsync should only be used to filter for a specific player, hence the need for the player id. FilterStringForBroadcast filters it for general use, such as broadcasting, so you don’t need to filter for every player.