I need help deleting messages/sent Commands from chat

I’ve made Command Detection System. All I want to do is delete the message containing the command from the chat :slight_smile: because I’m clawing my eyes out desperate for a solution

local Players  = game:GetService("Players")

local Output = script.Parent.Events.SendCommands

local prefix = '/' -- Change to whatever

local gameCreatorID = game.CreatorId

local OppedIDs = require(script.Parent.OppedPlayerIDs)

local function isIn(UID, storedIDs)
	for k, ID in pairs(storedIDs) do
		if ID == UID then
			return true
		end
	end
	return false
end

local CommandList = 
	{
		[1] = "op",
		[2] = "spectate",
		[3] = "kick",
		[4] = "ban"
	}

-- Text Command Detector --
Players.PlayerAdded:Connect(function(Player)
	
	local playerID = Player.UserId
	
	Player.Chatted:Connect(function(text, plr)
		
		if isIn(playerID, OppedIDs) or playerID == gameCreatorID then

			local lengthOfCommand = string.len(text)
			local prefixGuard     = string.sub(text, 1, 1)
			local UnsplitCommand  = string.lower(string.sub(text, 2, lengthOfCommand))

			if prefixGuard == prefix then

				for k, CommandGuard in pairs(CommandList) do
					if string.find(UnsplitCommand, CommandGuard) then

						Output:Fire(UnsplitCommand, plr)
						
						--Message Deleter here.
					end
				end
			end
		end
	end)
end)

Rather than deleting the message from the chat itself, you want the script to read the message and immediately destroy it, preventing chat from picking it up.

I’ve seen systems like this in the past, but I’m not sure how to make one. I’d do some research.

is there a particular service that gets the message before it’s sent to the chat?

I believe so.

Chars

Maybe use TextChatCommands.
https://create.roblox.com/docs/reference/engine/classes/TextChatCommand

Here is a basic example:

local Players = game:GetService("Players")
local TextChatCommandFolder = game:GetService("TextChatService"):WaitForChild("TextChatCommands")

local NewCommand = Instance.new("TextChatCommand", TextChatCommandFolder)
NewCommand.Name = "Ban"
ResetCoinsCommand.PrimaryAlias = "/ban"
ResetCoinsCommand.Enabled = true


NewCommand.Triggered:Connect(function(plrtextsource, chattext)
    local player = Players:FindFirstChild(plrtextsource.Name)
    --The rest of your command here.
end)

Are you using the new TextChatService or the old chat service?

I’m using the player.chatted event so I can get the player’s id and message so I can process it into a command for another script to run through. I’ve made some improvements and here’s the new script:

local Players      = game:GetService("Players")
local OppedIDs     = require(script.Parent.OppedPlayerIDs)
local CommandList  = require(script.Parent.Commands)
local Input        = script.Parent.Events.SendCommands

local function IDCheck(UID)
	
	for k, IDGuard in pairs(OppedIDs) do
		if IDGuard == UID then
			return true
		end
	end
	return false
end


Players.PlayerAdded:Connect(function(Player)
	
	local PlayerID   = Player.UserId
	local PlayerName = Players:GetNameFromUserIdAsync(PlayerID)

	Player.Chatted:Connect(function(text)

		if IDCheck(PlayerID) then

			local UsedPrefix= string.sub(text, 1, 1)
			local UnsplitCommand = string.sub(text, 2, string.len(text))

			for k, Prefixes in pairs(CommandList.Prefixes) do

				if UsedPrefix == Prefixes then

					for k, CommandGuard in pairs(CommandList.Commands) do -- just to see if the command said is actually a command

						if string.find(UnsplitCommand, CommandGuard) then

							Input:Fire(UnsplitCommand, Player)		
						end
					end
				end
			end
		end
	end)	
end)

it there’s another way of detecting if a player said something that is more reliable than this method then I’ll be open to it!

this does not work with my type of command script. but thanks for letting me know about it.