Player.Chatted:Connect(function(chatmessage)
FiltersAreActualDooDooService = game:GetService("TextService")
local WhatHeSaid = chatmessage
repeat
wait()
local succ, err = pcall(function()
WhatHeSaid = FiltersAreActualDooDooService:FilterStringAsync(WhatHeSaid, Player.UserId)
end)
if err then
print(err)
else
print(WhatHeSaid)
end
until succ
--...
It’s going good, and then I see what “WhatHeSaid” printed as.
Don’t clean your glasses or wipe your screen. It returned an INSTANCE.
What am I supposed to do with this? I wanted a string. What is this?
When something is unintuitively giving you something you don’t recognize, I recommend you do tons of research and stay inquisitive so that it eventually makes sense on your own.
For example, if a function is returning an instance and you don’t know why, you could probably print its .ClassName property, which every instance has, so that you can look that up on the dev wiki.
A note in the future that you should try and make use of protected calls properly - or rather, in such a way that’s readable and maintainable. The loop is unnecessary because you’re not going to get a success return by repeatedly calling the method. Furthermore, you should wrap the method instead of an anonymous function.
local TextService = game:GetService("TextService") -- Don't put this in the function
Player.Chatted:Connect(function (ChatMessage)
local success, result = pcall(TextService.FilterStringAsync, TextService, ChatMessage)
if not success then
warn(result)
else
print(result)
end
-- ..
end)
The only method you need to wrap in a protected call is the FilterStringAsync method as internally it is a web call. Once you get the TextFilterResult object back from FilterStringAsync, any of the methods you call are guaranteed to succeed as they simply return strings that were passed to TextFilterResult.