Filtering error, instance warning

After reading a roblox article on filtering I tried to make a remote event,

game.ReplicatedStorage.Movement.SendChat.OnServerEvent:Connect(function(player, message) 
	local TextService = game:GetService("TextService")
	local filteredmessage
	local success, errorMessage = pcall(function()
		filteredmessage = TextService:FilterStringAsync(message, player.UserId)
		
		player:FindFirstChild("PlayerPosition"):SetAttribute("Chat", filteredmessage)
		player:FindFirstChild("PlayerPosition"):SetAttribute("Chatting", true)
		player:FindFirstChild("PlayerPosition"):SetAttribute("Emote", false)
		
		local plr = player.Name
		game.ReplicatedStorage.Movement.RecieveChat:FireAllClients(plr, filteredmessage)
		wait(5)
		if game.Players:FindFirstChild(player.Name) then
			if player:FindFirstChild("PlayerPosition"):GetAttribute("Chat") == filteredmessage then
				player:FindFirstChild("PlayerPosition"):SetAttribute("Chatting", false)
			end
		end
	end)
	if not success then
		warn("Error filtering text:", message, ":", errorMessage)
	end
end)

For some reason I am getting this error

1 Like

What happens is that FilterStringAsync returns TextFilterResult, which is an instance, you must use one of its functions

local Service = game:GetService("TextService")
game:GetService("ReplicatedStorage").Movement.SendChat.OnServerEvent:Connect(function(player, message) 
	--		Get TextFilterResult
	local success1, Result = pcall(Service.FilterStringAsync, Service, message, player.UserId)
	if not success1 then
		warn("Error filtering text:", message, ":", Result)
		return
	end

	--		Get filtered text
	local success2, filteredmessage = pcall(Result.GetNonChatStringForBroadcastAsync, Result)
	if not success2 then
		warn("Error filtering text:", message, ":", filteredmessage)
		return
	end

	--		Continue if everything is alright
	player.PlayerPosition:SetAttribute("Chat", filteredmessage)
	player.PlayerPosition:SetAttribute("Chatting", true)
	player.PlayerPosition:SetAttribute("Emote", false)

	local plr = player.Name
	game:GetService("ReplicatedStorage").Movement.RecieveChat:FireAllClients(plr, filteredmessage)
	task.wait(5)
	
	if player.PlayerPosition:GetAttribute("Chat") == filteredmessage then
		player.PlayerPosition:SetAttribute("Chatting", false)
	end
end)

I use GetNonChatStringForBroadcastAsync as it is for everyone.

2 Likes