RemoteEvent on client side is not responding to the ClientEvent

Hello everyone! Since chat was blocked in Russia, I decided to create my own place to chat. I developed a system that works like this: a client sends a text message to the server, and the server sends the message to all clients in a specific area (to ensure privacy).


explorer2

--Client UI
replicatedstorage = game:GetService("ReplicatedStorage")
local eventClientUI = replicatedstorage:WaitForChild("eventClientUi")
local eventText = replicatedstorage:WaitForChild("eventText")
local textBox = script.Parent.Parent

eventClientUI.OnClientEvent:Connect(function()
	textBox.Visible = true
end)
script.Parent.MouseButton1Click:Connect(function()
	eventText:FireServer(textBox.Text)
	print("eventText Fired Server, Text: " .. textBox.Text)
end)
--Server Script inside the Table1
replicatedstorage = game:GetService("ReplicatedStorage")

local eventText = replicatedstorage:WaitForChild("eventText")
local eventClientUI = replicatedstorage:WaitForChild("eventClientUi")
local eventClientText = replicatedstorage:WaitForChild("eventClientText")

local playersInBox = {}

local TouchBox = script.Parent.TouchBox
TouchBox.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if not table.find(playersInBox, player) then
			table.insert(playersInBox, player)
		end
	end
end)
TouchBox.TouchEnded:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if table.find(playersInBox, player) then
			table.remove(playersInBox, table.find(playersInBox, player))
		end
	end
end)

local sign = script.Parent.sign
local screen = sign.screen

screen.ClickDetector.MouseClick:Connect(function(Player)
	if table.find(playersInBox, Player) then
		eventClientUI:FireClient(Player)
	end
end)

eventText.OnServerEvent:Connect(function(Sender, Text)
	print("eventText OnServerEvent, Text: " .. Text .. " Sender: " .. Sender.Name)
	print(playersInBox)
	for i, player in ipairs(playersInBox) do
		eventClientText:FireClient(player, Text, Sender)
		print("eventClientText fired client " .. player.Name .. " Text: " .. Text .. " Sender: " .. Sender.Name)
	end
end)

--Client script inside the scrolling frame
replicatedstorage = game:GetService("ReplicatedStorage")
local eventClientText = replicatedstorage:WaitForChild("eventClientText")
eventClientText.OnClientEvent:Connect(function(Text, Player)
	print("eventClientText Got OnClientEvent " .. "Text: " .. Text .. "Sender: " .. Player.Name)
	local message = Instance.new("TextLabel")
	message.Text = Player.Name .. ": " .. Text
	message.Parent = script.Parent
	message.TextColor3 = Player.TeamColor.Color
	message.TextStrokeTransparency = 0
	message.TextStrokeColor3 = Color3.new(0, 0, 0)
	message.TextScaled = true
	message.Font = Enum.Font.SourceSansBold
	message.BackgroundTransparency = 1
	message.Size = UDim2.new(1, 0, 0.1, 0)
	message.Position = UDim2.new(0, 0, 0, 0)
end)

eventClientText is not responding to the eventClientText:FireClient


I cant understand why it isnt responding, please help me fix it.

I can’t see anything clearly wrong with your script. Could you put a print just before you establish the connection for eventClientText to ensure the remote is being listened for?

Also, please exercise extreme caution when implementing a custom chat. Make sure it properly adheres to Roblox’s text filtering standards. If it doesn’t, your game and possibly account could face moderation.

Okay, print does not show in the console and that creates even more confusion.



P. S. thanks for reminding about text filtering!

Is the LocalScript ClientText in a place where it can run? If not, you can create a regular Script and set its RunContext to Client. Although, I would recommend putting ClientText somewhere like StarterPlayerScripts and just referencing the instances it needs from there for the sake of organization. Either way works, though.

For testing, ive moved ClientText to the Table1(see the explorer screenshot in the original post). And now it works!


If you can, please explain how to make text filtering work. Ive made this(code below) and it doesnt seem to work, allowing any text to go through.

eventText.OnServerEvent:Connect(function(Sender, Text)
	print("eventText OnServerEvent, Text: " .. Text .. " Sender: " .. Sender.Name)
	print(playersInBox)
	local filterResult = getFilterResult(Text, Sender.UserId)
	if filterResult then
		local success, filteredText = pcall(function()
			return filterResult:GetNonChatStringForBroadcastAsync()
		end)
		if success then
			print("FILTERED:", filteredText)
			for _, player in pairs(playersInBox) do
				eventClientText:FireClient(player, filteredText, Sender)
				print(filteredText)
				print("eventClientText fired client " .. player.Name .. " Text: " .. filteredText .. " Sender: " .. Sender.Name)
			end
		else
			warn("Error filtering text!")
		end
	end
end)

Text filtering generally doesn’t work in the Studio testing environment. You either have to run the game in a Team Test or live server for filtering to work.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.