I wanna create a Global Announce command in cmdr!

  1. What do you want to achieve?
    I wanna make a global announcement cmd in Cmdr panel
  2. What is the issue?
    Can’t seem to figure out how to
  3. What solutions have you tried so far?
    I have tried coding it myself but could not i would like any kind of help
-- This is an example Lua code block

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!

1 Like

It works well thanks. You did make a crucial mistake though, you made onserverevent on a client script which i have fixed as of now. I like some assistance of some kind with cmdr panel


this is a module script that handles all the args,

this handles all the scripts. I will try to do it myself but im not that good of a scripter as i started recently so i would love some help. Thank you. @TriumphantCreatorX

I know it may sound strange, but OnServerEvent is an event that must only be triggered from the client. The naming logic here is “on the server event” or “once the server fires the RemoteEvent.” And of course, OnClientEvent is an event that can only be triggered from the server.

Also you can install Cmdr through their GitHub releases. From there, I don’t know much else about Cmdr…

I am just checking in, is everything working as normal?