Why is the message not displayed?

Hi, maybe you can help me :slight_smile: .
I would like a message from system to appear in the chat with a previously defined text at the push of a button. Every player should see the message.

Script of the Button:

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.Parent.Parent.Parent.Events.SystemAnnounceEvent:FireServer(script.Parent.Parent.Parent.ReasonBox.Text, script.Parent.Parent.Parent.ReasonBox.Text)
end)

Script of the Event:

script.Parent.Parent.Parent.Parent.Events.SystemAnnounceEvent.OnServerEvent:Connect(function(player, input, reason)
	local messagetext = input
	game.StarterGui:SetCore("ChatMakeSystemMessage", {
		Text = messagetext;
		Font = Enum.Font.SourceSansSemibold;
		Color = Color3.new(1, 0, 0)
	})
end)

Both scripts are in local scripts
PinoRisi

I think the script that has the event should be a regular script, not a local script

Edit: okay now that I actually read it well, yea I think bindableevents are the way to go in this case if it’s client to client communication

use bindable events to call from server to server or client to client

Like above, I suggest you are using a local script trying to communicate the server and making a message, I suggest doing client-server-clients stuff, for example:
client sends info to server using Remote:FireServer(), server retrieves it, server send info to every other client using Remote:FireAllClients(), clients recieved it with .OnClientEvent, do stuff

Solution: This needs to be a Script, not localscript.

Also recommend defining variables like so:

local parent = script.Parent.Parent.Parent
local event = parent.Parent.Parent.Events.SystemAnnounceEvent
local reason = parent.ReasonBox

script.Parent.MouseButton1Click:Connect(function()
	event:FireServer(reason.Text, reason.Text)
end)

When I use a localscript, :SetCore doesn’t work anymore.

And besides, I can’t use FireServer () with BindableEvents:
“FireServer is not a valid member if BindableEvent”

Use :Fire instead, and to connect it is .Event:Connect()

Edit: BindableEvents and RemoteEvents are different, BindableEvents are for client-client and server-server signals, while RemoteEvents are for client-server, server-client, client-server-client and server-client-server signals

My script now looks like this:

local parent = script.Parent.Parent.Parent
local event = parent.Parent.Parent.Events.SystemAnnounceEvent
local reason = parent.ReasonBox

script.Parent.MouseButton1Click:Connect(function()
	event:Fire(reason.Text, reason.Text)
end)

The other Script:

script.Parent.Parent.Parent.Parent.Events.SystemAnnounceEvent:Connect(function(player, input, reason)
	local messagetext = input
	game.StarterGui:SetCore("ChatMakeSystemMessage", {
		Text = messagetext;
		Font = Enum.Font.SourceSansSemibold;
		Color = Color3.new(1, 0, 0)
	})
end)

I don’t have any errors either. But it still doesn’t work.
What do I have to change now to make it work?

1 Like

Hey! I’ve changed some of your codes. You can follow the instructions:

  1. Add RemoteEvent to Replicated Storage and rename it “SystemMessageController”.

Remote event

  1. Then, add “ScreenGui” to StarterGui. Next, add “TextButton” into ScreenGui and the final one, add “Script” into TextButton.

Starter gui

  1. You can customize your button but I’m explaining the simplified one now.

  1. Go to StarterPlayer > StarterPlayerScripts and add “LocalScript” into it.

ChatSystemMessage

  1. Now, copy and paste this script into TextButton’s script;

    local player = game.Players.LocalPlayer
    local button = script.Parent
    local SystemMessageController = game.ReplicatedStorage.SystemMessageController
    script.Parent.MouseButton1Click:Connect(function()  -- It checks if mouse button is clicked
          local message = "TRIAL"  -- You can write something else instead of "TRIAL".
          SystemMessageController:FireAllClients(message) -- Makes it appear for all the players.
    end)
    
  2. Finally, copy and paste this code into StarterPlayer > StarterPlayerScripts

    game.ReplicatedStorage.SystemMessageController.OnClientEvent:Connect(function(message)
       game.StarterGui:SetCore("ChatMakeSystemMessage", {
          Text = message, -- System makes the written message appear in the chat
          Font = Enum.Font.Antique,   -- Changes the font of the text
          Color = Color3.fromRGB(0, 255, 0),    -- Changes the color of the text
          TextSize = 18,  -- Changes the size of the text
       })
    end)
    

Here is how it works;

robloxapp-20210312-1520111.wmv (474.1 KB)

EDIT: You can try it with two accounts.

I hope this helped you!