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?