How would I remove new lines from this chat tag?

This script currently takes the text from a textbox and places it before a player’s username in chat.

Unfortunately, when you add new lines using ctrl + J, it will too add it to your chat tag. I can limit the amount of text they add, but I don’t know how to completely remove of new lines.

I don’t know what to exactly search on the forum, but I have skimmed over some similar topics and none of them seem too applicable. It’d really help to know what I should be looking for/what to change.

This is the code that applies the custom name that has already been filtered as a chat tag.

textChatService.OnIncomingMessage = function(message: TextChatMessage)
	local properties = Instance.new("TextChatMessageProperties")
	if message.Status == Enum.TextChatMessageStatus.Success then
		if message.TextSource then
			local textplayer = game:GetService("Players"):GetPlayerByUserId(message.TextSource.UserId)
			if textplayer.Character.NameLabel.TextBox.Text ~= nil then
				local colorvalue = textplayer.Character.NameLabel.TextBox.TextColor3
				properties.PrefixText = string.format("<font color='#%s'", colorvalue:ToHex()) .. string.format(">[%s] </font>", textplayer.Character.NameLabel.TextBox.Text) .. textplayer.DisplayName .. ": "
			end
		end
	end
	return properties
end

Hello! After some testing, I see that the issue is in
string.format(">[%s] </font>", textplayer.Character.NameLabel.TextBox.Text)
If you could tell me what this is, I could gladly fix this script for you!

There is nothing particularly wrong with it, Im only asking how I would go about removing the lines from chat created by typing ctrl+j. Basically, I want all of the chat tag’s text on one line no matter what.

That part of the script adds the tag behind the player’s username.

I’m kinda bad at string formats and that stuff, but the best i can advice you to do is to replace any “\n” with a regular space character using string.gsub()

kinda like this:

local stringWithRemovedLineSkip = string.gsub(TextString,"\n"," ")--replaces with a regular spacebar
3 Likes

Thank you! This works perfectly.

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