Problem with customizing Roblox Chat using custom command

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to be able to use a command to modify the “speaker” name when using a command in chat.
    For example, ;chat Admin Hello!
    Output: [Admin] Hello!

  2. What is the issue?
    I’m attempting to try to retrieve the message and check to see if the first word is “;chat”. However, I am only able to detect the message from the player that is messaging, but the message results as nil when the other player’s script attempts to find the message

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have attempted to look in the table called “messageData” which shows the detail of the message detail which I think is one step closer to the solution, but I still need help on finding the chat.

-- This code is located in game.Chat.ClientChatModules.MessageCreatorModules.DefaultChatMessage
-- Code modified is inside function "CreateMessageLabel"
function CreateMessageLabel()
    local message = messageData.Message

    local formatUseName = string.format("[%s]", speakerName)
    -- Format: ;chat SomeNameHere This is a sample text
	if message ~= nil then -- message is nil for non speakers
		if messageData.MessageLengthUtf8 > 5 then
			if string.sub(message, 1, 5) == ";chat" then
				local stringTable = string.split(message, " ")
				formatUseName = "[" .. stringTable[2] .. "]"

Result (only for the speaker, the nonspeaker is left unchanged):

Update: I found another closer solution in term of detecting the message inside this function within the same function:

local function UpdateTextFunction(messageObject)
		if messageData.IsFiltered then
			BaseMessage.Text = string.rep(" ", numNeededSpaces) .. messageObject.Message
			local messageLength = messageObject.MessageLengthUtf8 or messageObject.MessageLength
			BaseMessage.Text = string.rep(" ", numNeededSpaces) .. string.rep("_", messageLength)
        -- In the output, this print nil for the nonspeaker
        -- However, this somehow fired again and return the actual message
1 Like