Delete chat message a bit buggy

Hi there! I am creating some admin commands for my game, and I have a pretty decent delete chat message script. However, not only does it delete the message in the chat, it also deletes the first message in the chat box. This is very strange, and I have no idea how to fix it, as I am not very good at chat manipulation (This script is from a post)

Edit: This is in a module script in the ClientCommands folder in chat.

local util = require(script.Parent:WaitForChild("Util"))

local cmds = {
	"/";
}

local function hasKeyword(s)
	for _, keyword in ipairs(cmds) do
		if (s:find(keyword, 1, true)) then
			return true
		end
	end
	return false
end

function ProcessMessage(message, ChatWindow, ChatSettings)
	if hasKeyword(message) then
		local currentChannel = ChatWindow:GetCurrentChannel()
		if (currentChannel) then
			currentChannel:RemoveLastMessageFromChannel()
		end
		return true
	end
end

return {
	[util.KEY_COMMAND_PROCESSOR_TYPE] = util.COMPLETED_MESSAGE_PROCESSOR,
	[util.KEY_PROCESSOR_FUNCTION] = ProcessMessage
}

You can try this out for yourself, and you will see that it deletes the first message as well.

Is there any possible way to fix this with the current system I am using. I know it is possible somehow, because games such as TOH have this.

Any help is greatly appreciated!

1 Like
local util = require(script.Parent:WaitForChild("Util"))

local cmds = {
	"/";
}

local function hasKeyword(s)
	for _, keyword in ipairs(cmds) do
		if (s:find(keyword,1,true)) then
			return true
		end
	end
	return false
end

function ProcessMessage(message,ChatWindow,ChatSettings)
	if hasKeyword(message) then
		local currentChannel = ChatWindow:GetCurrentChannel()
		return true
	end
	return false
end

return {
	[util.KEY_COMMAND_PROCESSOR_TYPE] = util.COMPLETED_MESSAGE_PROCESSOR,
	[util.KEY_PROCESSOR_FUNCTION] = ProcessMessage
}
1 Like

Wow, thank you so much dude, this helps a lot!

1 Like