Chat command doesn't work

I made a system, if a command is written into the chat, the message is painted in a certain color, but I have almost two of the same identical scripts, only the command is different, but they do not work. Only /me ​​works, I don’t understand why.

TextChatService.OnIncomingMessage = function(textChatMessage: TextChatMessage)
	if not textChatMessage.TextChannel then print("Ф") return nil end

	if string.sub(textChatMessage.Text, 1, 3) == "/do" then
		local overrideProperties = Instance.new("TextChatMessageProperties")
		overrideProperties.Text = string.format("<font color='#7726b5'>%s</font>", string.sub(textChatMessage.Text, 5))
		return overrideProperties
	end

	return nil
end

TextChatService.OnIncomingMessage = function(textChatMessage)
	if not textChatMessage.TextChannel then print("Ф") return nil end

	if string.sub(textChatMessage.Text, 1, 3) == "/me" then
		local overrideProperties = Instance.new("TextChatMessageProperties")
		overrideProperties.Text = string.format("<font color='#7726b5'>%s</font>", string.sub(textChatMessage.Text, 5))
		return overrideProperties
	end

	return nil
end

That’s because TextChatService.OnIncomingMessage is a callback. This means that it can only be assigned to once, otherwise it will be overridden by the new callback assigned to it. You need to put both into one function, and use an elseif statement or a table to decide which should come first.

TextChatService.OnIncomingMessage = function(msg)
    local properties = Instance.new("TextChatMessageProperties")
    
    if priority then
        --do stuff
    elseif otherPriority then
        --do stuff
    end
    return properties
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.