Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

How to make a Broadcast Chat Command?

Asked by 4 years ago

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.

0
downvoted for no attempt speedyfox66 237 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

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

Ad

Answer this question