How do I replace a letter in a player's message

So far the only solution I have found is replacing the whole player’s message. What I want to do is anytime a player has the letter L in their message, replace it with the letter E

local functionId = "editText"

local function doFilter(speaker, messageObject, channelName)

	if messageObject.Message == "L" then
		messageObject.Message = "E"
	end
end

local function runChatModule(ChatService)
	ChatService:RegisterFilterMessageFunction(functionId, doFilter)
end

return runChatModule

I’m guessing you want it for every L in a message.

You’ll want to look into string.gsub()

For this though, its pretty straightforward.

messageObject.Message = string.gsub(messageObject.Message, "L", "E")
--- "L" is the pattern, and "E" is what is replacing the pattern.

edit: I had E and L backwards

1 Like

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