Hello,
Global announcement commands do not come with Roblox games by default. If you are talking about global announcements that admin command systems use, then you will have to install a pre-built command system.
Popular admin command systems include:
Now, if you want to just make a global command system yourself, then I have made two scripts below to do this! An explanation of the steps is at the very bottom of this post.
Script in ServerScriptService
local AnnouncementCommand = ";announce" -- Not case-sensitive.
local AuthorizedUserIDs = {
4829339808 -- This is your user ID!
}
local AnnouncementDisplayer = nil -- Please replace nil with a RemoteEvent in ReplicatedStorage. If you need help with RemoteEvents, please send a reply.
local Players = game:GetService("Players")
local MessagingService = game:GetService("MessagingService")
Players.PlayerAdded:Connect(function(NewPlayer)
NewPlayer.Chatted:Connect(function(Message)
if string.lower(string.sub(Message, 1, string.len(AnnouncementCommand))) == string.lower(AnnouncementCommand) then -- The command has been sent.
if table.find(AuthorizedUserIDs, NewPlayer.UserId) then -- This player is authorized to use the command!
local AnnouncementContent = string.sub(Message, string.len(AnnouncementCommand) + 2)
MessagingService:PublishAsync("Global Announcements", AnnouncementContent)
end
end
end)
end)
MessagingService:SubscribeAsync("Global Announcements", function(Message)
print("Global announcement made: " .. Message.Data)
AnnouncementDisplayer:FireAllClients(Message.Data)
end)
LocalScript Parented Anywhere
(Preferably parented under a ScreenGui)
local AnnouncementDisplayer = nil -- Please replace nil with the same RemoteEvent that you used in the Handler script.
local AnnouncementTimeout = 5 -- In seconds.
local AnnouncementTextLabel = nil -- Please replace nil with a TextLabel that you want the announcement to display on. If you need help with the GUI, please send a reply.
AnnouncementDisplayer.OnServerEvent:Connect(function(Message)
AnnouncementTextLabel.Text = Message
AnnouncementTextLabel.Visible = true
wait(AnnouncementTimeout)
AnnouncementTextLabel.Visible = false
end)
Code Explanation
Server-Side Script
First, the server-side script in ServerScriptService acknowledges every player that joins the game using PlayerAdded. With that, the script can now acknowledge every new chat message. Once a player sends a chat message, the script will read the message content and check if the command, in this case, “;announce”, is used. If it is sent as the very first characters of the message, the script will then go down a step and check if the player has permissions to use the command from the AuthorizedUserIDs table. If the player is in the AuthorizedUserIDs table, the script will then send a cross-server message using MessagingService that a global announcement was made.
Within the same script, the global announcements are received and acknowledged from the MessagingService channel "Global Announcements". The script then fires a RemoteEvent to all clients to display the announcement on their GUIs.
Client-Side Script
This script is much simpler as it processes RemoteEvent messages from the server-side script to then convert them into text that the client can see on their GUI!
If you need any more explanations or more help, please send a reply!