I wanted to make a message broadcast in chat when you type a command, for example, the /me command. I know how to make a system message but no clue how to make this code. For example, I would type /announce hi in chat and "hi" would pop up in the chat as a system message.
✓ ANSWER ACCEPTED
How to make a Broadcast Chat Command?
1 answer
✓ Accepted answer
well you need to keep track of who is allowed to do commands, and then when they chat you process the command..
like this:
local admins = {"void_node", "builderman", "badcc", etc}
local Players = game:GetService("Players")
local commands = {
announce = function(msg)
print(msg)
end,
--add more command processors
}
Players.PlayerAdded:Connect(function(player)
for _, admin in pairs(admins) do
if(admin.Name:lower() == player.Name:lower()) then
player.Chatted:Connect(onChatted)
end
end
end)
function onChatted(msg)
local command = msg:match("^%\(%w+)");
local processor = commands [command]
if processor then
processor(msg:sub(#command + 1))
end
end
now if you chat something like this:
"/announce Server is shutting down" it will print in the output Server is shutting down
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
downvoted for no attempt