Help with chat command announcement

Hello, I would like to create a chat command that is:
/.announce [statement]
This would put an announcement onto everyone’s screen in the game

I’m not really sure how to do this, any ideas?

2 Likes

Hi, you would get what the player say then you would make the announce gui visible with the msg and the plr. Please mark this as the solution if it’s helped.

1 Like

I think he wants a script so it is not that helpful you basically just said that he needs to make it so when he says the annoucement the gui will be visible which is not the best explenation :slight_smile:

1 Like

You should add a script in ServerScriptService and use string.lower() to get the annoucement, then fire a event for all clients to show the gui. I’ll try to make the script and send you but for now here is a video from alvin blox which explains how to get the chat:
(249) MAKE ADMIN COMMANDS - Roblox Scripting Tutorial (Advanced) - YouTube

I’ll contact you soon with the script, good luck!

1 Like

It would only be to activate the frame from the PlayerAdded (plr) and all the players could see it as an announce?

script:

if Player.TeamColor == BrickColor.new("Lapis") then
			for i,Player2 in pairs(Players:GetPlayers()) do
				if message == '.announce' .. Player2.Name then
					print("The player name is ..." .. Player2.Name)
					-- code to announce here:
                    boolAnnounce = true --announce bool to activate
				end
			end
		end

plr script:

boolAnnounce = false
Players.PlayerAdded:Connect(function(Player)

if boolAnnounce == true then
--Show announce here
-- is it good?
end
end)

This would be nice, right? :scream:

You’d first need to handle the command on the client, fire a remote with all the arguments and then handle the rest on the server.

How it works on the server is that it clones the Announcement Interface to the PlayerGui of all the players inside of the server and also edits a StringValue with whatever you wanted announced. Then the LocalScript of the Announcement Interface handles that and displays whatever text you need.

This can also be done via FireAllClients but that would be more complicated.

Hello there!

I thin i understand what you want to do.

also: i wont spoonfeed you the scripts, you should learn the steps :slightly_smiling_face:

firstly, you would use the playeradded event to get the player, and use the chatted event to get the message. after this you would local message = string.split(message, “ “) and with that, you can index these words. get the first word by saying if message[1] == “text” then get the message by saving the second word to a variable. Next use a for i, v in pairs loop, looping through all of the players and creating a screengui and a textlabel showing your second message, after 5 seconds destroy the Gui.

sorry for the bad spelling, i’m on my phone :confused:

Hope this helped!

this can also be done completely on the server, since it uses PlayerAdded.

Sorry, this is really late. Anyways, you can do this using a RemoteEvent | Roblox Creator Documentation. Because you cannot send information to the client directly, you first have to send it to the server and then to all clients. Here is my reply to another topic that requires the same thing:

Now while that was for a random player on the players team, the concept of sending the information is the same. You need to have a gui set up for every player, although it doesn’t have to be visible. You can decorate it however you like, but you must have a TextLabel | Roblox Creator Documentation in it somewhere.

Also, in the other post it the message was being sent to a specific player. Because this is being sent to everyone on the server however, we need to use a Chat | Roblox Creator Documentation to filter the string.

In a local script inside the screen gui:

-- The remote event
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("AnnounceEvent")

local Gui = script.Parent

local AnnouncerLabel = Gui:WaitForChild("Frame"):WaitForChild("AnnouncerLabel") -- This is an example path to a TextLabel named AnnouncerLabel. This is optional and you can remove this if you wish
local AnnouncementLabel = Gui:WaitForChild("Frame"):WaitForChild("AnnouncementLabel") -- This is an example path to the TextLabel named AnnouncementLabel that will show your message. This is what you mainly want

-- function you use whenever you want to receive messages:
local function ReceiveMessage(announcer, message)
	Gui.Enabled = true
	AnnouncerLabel.Text = announcer
	AnnouncementLabel.Text = message

	wait(20) -- The amount of time to wait to allow the players to read the message

	Gui.Enabled = false
end

In a server script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Chat = game:GetService("Chat")

local RemoteEvent = ReplicatedStorage:FindFirstChild("AnnounceEvent") or Instance.new("RemoteEvent", ReplicatedStorage)
RemoteEvent.Name = "AnnounceEvent"

-- Function to call whenever the command is called
local function BroadcastMessage(player, message)
	message = Chat:FilterStringForBroadcast(message, player)

	RemoteEvent:FireAllClients(player.Name, message)
end