Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I'm trying to filter text for a direct messaging system. I only get nil?

I've never made a chat system before, thought just looking up the developer page would be easy. I'm certain my server script probably looks atrocious, so I appreciate any help.

Error message in the console.

15:29:53.262 - Script 'Players.Yokaoritu.PlayerGui.MessagingSystem.Frame.MainScript', Line 7
15:29:53.263 - Stack End
  nil
  15:29:53.264 - Players.Yokaoritu.PlayerGui.MessagingSystem.Frame.TS.LocalScript:3: bad argument #3 to 'Value' (string expected, got nil)
15:29:53.264 - Stack Begin
15:29:53.265 - Script 'Players.Yokaoritu.PlayerGui.MessagingSystem.Frame.TS.LocalScript', Line 3

Main Server Script

local TextService = game:GetService("TextService")
local filteredText = ""
game.ReplicatedStorage.onFilter.OnServerEvent:Connect(function(player, msg, rec, send, senderId)
	local TextService = game:GetService("TextService")
	local success, errorMessage = pcall(function()
		local filteredMessage = TextService:FilterStringAsync(msg, senderId)

		game.ReplicatedStorage.onFilter:FireAllClients(filteredMessage, send, rec, player)
		--msg = filteredMessage?
		--return?
	end)	
if not success then
	warn("Error filtering text:", msg, ":", errorMessage)
	-- Filter Failed
end
end)

Local Script that's supposed to be getting the message, it's getting Nil


game.ReplicatedStorage.onFilter.OnClientEvent:Connect(function(filteredMessage)
	print(filteredMessage)
	script.Parent.Value = filteredMessage --------- <----- This is the problem
	if script.Parent.Value == nil then
		print("Server Filter Returned Nil, There was an error.")
	end
end)

1 answer

✓ Accepted answer

I have attempted to implement TextService filtering in my previous projects as well yet kept retaining the same issues. I am unfamiliar with what's causing the problem, so if anyone has an idea, I will politely upvote your answer above mine as this is simply a work-around.

The Chat container of game contains a similar function FilterStringAsync, so I suggest that you use it instead for the time being:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local onFilter = ReplicatedStorage:WaitForChild("onFilter")

local ChatService = game:GetService("Chat")
local Players = game:GetService("Players")

onFilter.OnServerEvent:Connect(function(Sender, Msg, Rec, Send)
	local FitleredMessage
	for _,SendingTo in pairs(Players) do
		local Success, ErrorMessage = pcall(function()
			FilteredMessage = ChatService:FilterStringAsync(Msg, Sender, SendingTo)
	        end)
		if (Success) then
			onFilter:FireClient(SendingTo, Send, Rec, FilteredMessage)
		else
			warn("Error filtering text: '"..Msg..":", ErrorMessage)
		end 
	end
end)

1 comment

0

Thanks, I'll try to use this for now, I definitely gotta look into how other custom chats are filtered.

This discussion is preserved as it was. New answers, comments, and votes are closed.