Creating a chat announce command

Ever wanted to announce something in your game making sure that everyone can clearly see your message? Well, this will help you do that! Putting announcements in the game chat will allow your players to easily see all announcements. So let’s start…

First, you need to create a script parented to ServerScriptService and a RemoteEvent parented to ReplicatedStorage. Once you have done that, open up the script you just made and put this inside:

-- Gets the "chat" service. Required later for 'FilterStringForBroadcast'.    
local ChatService = game:GetService("Chat")

-- Gets the "ReplicatedStorage" service.
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Gets the RemoteEvent that you created earlier.
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

Now that you have declared some variables, let’s get down to the code that does all the magic. First, add this to your script:

game.Players.PlayerAdded:Connect(function(player) -- This event fires whenever someone joins your game.
	player.Chatted:Connect(function(message) -- This event fires whenever someone says something in the game chat.          
        local args = message:split(" ") -- Splits arguments.
        if args[1]:lower() == "/cann" then -- Checks if the command was used.
            local announcemsg = message:sub(args[1]:len() + 2,-1) -- Announce message in a variable.
            local filteredannouncemsg = ChatService:FilterStringForBroadcast(announcemsg, player) -- Filters the message with the chat filter system. (Required by Roblox!)
            wait(1) -- Waits 1 second so that the announce message is not sent to everyone before your command message.
            RemoteEvent:FireAllClients(filteredannouncemsg) -- Fires the RemoteEvent you created earlier.
        end
    end)
end)

So now that you have the script working, it’s time to create a localscript parented to StarterPlayerScripts. Once you have created it, put this in:

-- Gets the "ReplicatedStorage" service.
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Gets the RemoteEvent that you created earlier.
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent") 

Now all you have to do is put this in and you are done:

local function OnEventFired(filteredannouncemsg) -- Function that will be called when your RemoteEvent is fired.
       game.StarterGui:SetCore("ChatMakeSystemMessage", { -- Creates a chat message.
       Text = filteredannouncemsg, -- The text of the announcement that will be sent.
       Color = Color3.fromRGB(66, 194, 245), -- The text color of the announcement that will be sent.
       TextSize = 30 -- The text size of the announcement that will be sent.
    })
end

RemoteEvent.OnClientEvent:Connect(OnEventFired) -- Calls the function above when your RemoteEvent is fired.

You have finished creating the chat announce system! Congrats! :clap: :clap:
I hope that people learn from this guide.

Read Me:

  • ‘pcall’ was not used.
  • By default, /cann is the command to announce something in chat.
  • There are no restrictions for the command by default (place owner only, admin team only). You must add them yourself.

Result:

defresultcas

20 Likes

Would I be able to implement this into a ScreenGui?

Hello :wave:
This is a good tutorial to make a simple chat announcer!
I just want to tell you that you forgot to close events at the end of the server side script.

2 Likes

Nice tutorial. How can I change the cann? I want it to work when I type /say. And is there a way to delete the command message?

at the 2 script he shares where it says if args[1]:lower() == "/cann" then change that cann to "/say"

2 Likes

I tried that. But I did

if args[1]:lower() == “/Say” then and it didn’t work but it works now thank you.

Fixing that. Thank you for telling me!

1 Like

Unfortunately, you wouldn’t. This uses SetCore.

From Vong25:

I think they can implement this into a ScreenGui by just changing the OnEventFired function to set the text of a TextLabel to filteredannouncemsg.

1 Like

I think they can implement this into a ScreenGui by just changing the OnEventFired function to set the text of a TextLabel to filteredannouncemsg.

1 Like