OnClientEvent isn't going to listen to FireAllClients

Hello. I am making a custom chat system, I tried to make it as simple as possible. But, OnClientEvent isn’t listening to :FireAllClients(), I tried to even test it out with prints, and it is not going to work. Here’s my code:

The ServerScript:

local players = game:GetService("Players");

players.PlayerAdded:Connect(function(player)
	
	if player ~= nil then
		
		player.Chatted:Connect(function(message, recipent)
			
			local replicatedStorage = game:GetService("ReplicatedStorage");
			
			for _, v in ipairs(replicatedStorage:GetChildren()) do
				
				if v:IsA("RemoteEvent") and tostring(v.Name) == "ChatRemote" then
					
					v:FireAllClients(tostring(message))
				end
			end
		end)
	end
end)

The LocalScript:

game.ReplicatedStorage.ChatRemote.OnClientEvent:Connect(function(message)
	
	print(message)
	
	local chat = script.Parent.Chat;
	
	local chatFrame = chat.Chat;
	
	local messages = 0
	
	for _, v in ipairs(chatFrame:GetChildren()) do
		
		if v:IsA("TextLabel") then
			
			if tostring(v.Name) ~= "Example" then
				
				messages = messages + 1
			end
		end
	end
	
	if messages < 11 then
		
		local messageClone = chatFrame.Example:Clone();
		
		messageClone.Parent = chatFrame
		
		chatFrame.CanvasPosition = chatFrame.CanvasPosition + Vector2.new(0, 0.1)
		
		messageClone.Text = "Test worked."
	end
end)

The ServerScript is in ServerScriptService and the LocalScript is in StarterGui. Any help?

You’re using FireAllClients on a different remote event from the one in the LocalScript. The one you’re listening to on the local script is called Remote, while you’re checking if the one you fire to is named ChatRemote.

1 Like

I did not notice, but it still didn’t fix my error. The remote isn’t being fired for some reason, is there another mistake I’ve done?

Can you edit your original post with the fixed version of your code (or put it in a new post)? It’s easier to find the issue if I can see the code, since there are a couple ways I can think of that might seem like they fix it but not work properly.

2 Likes

Yes, I am editing my post at the moment…

1 Like

I found a solution for this. I just performed the actions on the Server.