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!
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: