Chat Script - Roblox Bug or an issue with my code?

Hello!

I’m currently working on admin panel. This admin panel is activated by a specific message command, followed by server sided checks to ensure the user is admin.

However, when an admin opens this panel, I configured the Roblox Chat API to remove the message from the message channel, as soon as the message was sent, following exactly what it had in their API document (here).

It all works so far, I say the command and it shows the UI. However, as soon as I close the UI, and attempt to open it again, I get an error from a Roblox Script:

MessageLogDisplay:109: attempt to index nil with 'Destroy'

My message never get’s sent, which is the point, but this error keeps coming up, and I have no idea what could be causing it.

This is affecting the popup times of the UI, as the error throws, the actual UI never comes up (I do have a cooldown in place to prevent spamming).

Here is the code module, located in the Client Chat Modules (as the API said).

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

function ProcessMessage(message, ChatWindow, ChatSettings)
	if string.sub(message, 1, 6):lower() == "temp101" then
		local currentChannel = ChatWindow:GetCurrentChannel()
		if (currentChannel) then
			currentChannel:RemoveLastMessageFromChannel()
		end
		return true
	end
	return false
end

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

I dont think you need to remove the last message as if true is returned, it alreayd prevents the message form being sent

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

function ProcessMessage(message, ChatWindow, ChatSettings)
	if string.sub(message, 1, 6):lower() == "temp101" then
		return true
	end
	return false
end

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

Also unrelated to the bug, but you’re trying to compare a 6 character sub with a 7 character string

1 Like

Hello!

Thanks for the response, I was going off the true as it had it in the API.

The code I have is different to the one I posted here, just to keep the access code private.

Your fix seems to have worked, thanks so much, have a great day.

1 Like