I have a small question about player.Chatted function.
How could you make it so once someone types “/admin” in chat, the message doens’t actually get sent. (For example: if you were to type “/console” in the chat, the dev console will open but no message in the chatbox of ROBLOX)
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
if msg == "/admin" then
game.ReplicatedStorage.RemoteEvent:FireClient(plr)
end
end)
end)
I have this small starter-script which I simply made.
Oh, that can be done by tampering with the Chat system a little bit. It’s easy though.
Step 1: Create a folder called “ClientChatModules” inside the Chat service (Service image below)
Step 2: Create a folder called “CommandModules” inside the folder you previously created in step 1.
Step 3: add a BoolValue inside the folder you previously created in step 2 and name it “InsertDefaultModules”.
Step 4: Add a ModuleScript inside the folder you created in step 2, and paste this in:
local util = require(script.Parent:WaitForChild("Util"))
local replicatedStorage = game:GetService("ReplicatedStorage")
local adminEvent = replicatedStorage.AdminEvent
local commands = { "your", "command", "names" }
local prefix = "/"
local function ProcessMessage(message, cw)
if message:sub(1, #prefix) ~= prefix then
return false
end
local args = message:split(" ")
local cmd = args[1]:sub(#prefix + 1, #args[1]):lower()
table.remove(args, 1)
if not table.find(commands, cmd) then
return false
end
adminEvent:FireServer(message, args, cmd)
return true
end
return {
[util.KEY_COMMAND_PROCESSOR_TYPE] = util.COMPLETED_MESSAGE_PROCESSOR,
[util.KEY_PROCESSOR_FUNCTION] = ProcessMessage
}
Step 5: Add a RemoteEvent called “AdminEvent” inside of ReplicatedStorage.
You can handle your admin from a server-sided script by listening to AdminEvent.OnServerEvent. The parameters passed are the Player by default, the message, arguments passed and finally, the command name that the player invoked.
This was something that I did for the admin in my game, feel free to adjust it according to your needs.