Why is my system chat message only being displayed to the LocalPlayer?

I made a script which should send a system message in the chat (TextChatService) for everyone to see, however it’s only showing the message to the local player.

Code: (not full)

Client:

CreateMsg:FireServer()

local msgEvent

local function sendMsgToChat(player, message)
	task.wait()
	Channel:DisplaySystemMessage("<font color='#41CD50'>"..message.." completed bla bla bla"</font>")
	msgEvent:Disconnect()
end

msgEvent = sendMsg.OnClientEvent:Connect(sendMsgToChat)

Server:

CreateMsg.OnServerEvent:Connect(function(player)
	sendMsg:FireAllClients(player, player.DisplayName)
end)

How could I fix this so everyone in the server can see the message?

2 Likes

Probably because you disconnect the event after.

Fixed client code:

CreateMsg:FireServer()

local function sendMsgToChat(player, message)
	task.wait()
	Channel:DisplaySystemMessage("<font color='#41CD50'>"..message.." completed bla bla bla"</font>")
end

sendMsg.OnClientEvent:Connect(sendMsgToChat)
3 Likes

The reason why I disconnect the event is to prevent the RemoteEvents from stacking. I did try your code tho, what happened was that after the 1st time the event was fired, 1 message was sent in the chat, after the 2nd time, 2 messages were sent into the chat. It also didn’t fix the issue that only the local player would see it. Ty anyways!

2 Likes

You need to use the FireAllClients() method instead of FireServer(). This will send the message to all connected clients, not just the local player.

2 Likes

Use can’t use FireAllClients on a client + he already does do that

2 Likes

I think I see the issue, when using :FireAllClients, you don’t need the extra player argument at the beginning, remove that and it should work.

2 Likes

No, you cannot use FireAllClients on a client. FireAllClients is a server-side command that is used to disconnect all clients from the server.

2 Likes

So it should be:

FireAllClients();

2 Likes

I think you should keep the sendMsg connected the whole time, if not then how each client would receive the FireAllClients from that event?

If you dont want the messages to be stacked, or you use a debouce in server to just allow one message each x seconds, or create a queue system in client or in server to display messages in order

2 Likes

Sorry? FireAllClients() to disconnect all clients from server? Its just to fire a remote to all clients in server, not to disconnect them, or you mean, OP should use it to disconnect the remote?.. i dont get it…

3 Likes

You can send any amount of values when using the remote and FireAllClients().
Only FireClient(player), is the one that matters in which the first argument is the important one, for FireAllClients(true, false, player, part, stuff, etc) can be used, idk why OP is sending the player as first argument, maybe cause OP needs the player that triggered the message as first argument.

As shown in OP’s function: sendMsgToChat(player, message)
So FireAllClients(player, player.DisplayName) player is the player, and DisplayName is the “message”

2 Likes

Thank you everyone, it seems to be working now!

What did I do wrong?

  • The script which created the message (sendMsgToChat) was inside another function, which was inside a deactivated script. I moved it outside in a seperate script
  • Disconnecting the event was completely useless, as the bug which sent multiple messages the more often the RemoteEvent was used fixed itself now?
Fixed Version

LocalScript inside a button:

script.Parent.MouseButton1Click:Connect(function()
	CreateMsg:FireServer()
end)

LocalScript inside StarterPlayerScripts:

local function sendMsgToChat(player, message)
	task.wait()
	Channel:DisplaySystemMessage("<font color='#41CD50'>"..message.." clicked a button lol</font>")
end

sendMsg.OnClientEvent:Connect(sendMsgToChat)

Script inside ServerScriptService:

CreateMsg.OnServerEvent:Connect(function(player)
	sendMsg:FireAllClients(player, player.DisplayName)
end)

I hope this can help anyone who has the same problem in the future!

5 Likes

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