Some problem with chat remotes for filtering

I’m sorry if this title is confusing, but i have no idea on how to call this problem, it honestly is hard for me to describe, so please look for yourself…

I want to achieve that if you put a text into a textbox and you press enter, that it will go through filtering and gets sent back as the filtered version and creates a chat system message with the filtered string

localscript:

local TextBox = script.Parent
local Button = script.Parent.Parent.TextButton
local localplayer = game:GetService("Players").LocalPlayer
local FilterEvent = game:GetService("ReplicatedStorage").Events:WaitForChild("FilterEvent")

local function SendMessage(message)
	warn("Message sent")
	game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage",{
		Text = "["..localplayer.Name.."]: ".. message,
		Color = Color3.fromRGB(150, 177, 255)
	})
end

FilterEvent.OnClientEvent:Connect(function(Player,message,forwhat)
	if forwhat == "Custom chat" then
		warn("Fired from the server")
		return SendMessage(message)
	end
end)

TextBox.FocusLost:connect(function(enterPressed)
	if enterPressed then
		warn("Server fired")
		FilterEvent:FireServer(script.Parent.Text,"Custom chat")
	end
end)

Script:

local TxtService = game:GetService("TextService")
local FilterEvent = game:GetService("ReplicatedStorage").Events:WaitForChild("FilterEvent")

game.Players.PlayerAdded:Connect(function(Player)
	FilterEvent.OnServerEvent:Connect(function(filterMessage,forwhat)
		warn("Fired from client")
		if forwhat == "Custom chat" then
			warn("Got past forwhat")
			local message
			local success,errorMessage = pcall(function()
				message = TxtService:FilterStringAsync(filterMessage,Player.UserId)
				warn("Filtering...")
			end)
			if success then
				FilterEvent:FireAllClients(Player,message,"Custom chat")
				warn("Client fired".." ... ".."Filtering successful")
			else
				warn("Error while filtering "..filterMessage.." Error: "..errorMessage)
			end
		end
	end)
end)

Image1
Image2

If you want to reveive help please describe your problem, because I bet that no one is going to guess what is the purpose of your script, what is going on in it, what are you trying to achieve and what is working not as wanted. Please describe these things because having information only about two warns is too little.

You forgot player variable here:

FilterEvent.OnServerEvent:Connect(function(player, filterMessage, forwhat)

I know that i have to describe it, but i have no idea what you can call this problem neither how you describe it, i can only tell what i’m trying to achieve

I want to achieve that if you put a text into a textbox and you press enter, that it will go through filtering and gets sent back as the filtered version and creates a chat system message with the filtered string

Yeah i realized that to, i just added that because i’m used to do:

if player == localplayer then
  --code
end

Since i wasn’t able of using just FireClient

Yes this was the problem, thanks for helping!