Get rid of newline using scripts

I am making a custom chat system. But people can click enter before posting in chat and it creates a new line for some reason. How can I fix this? (I want to get rid of a new line when people send a message in my game.)

I know there are other posts, but none of them work for me, or I just don’t understand them. Here is a picture:
image

Roblox has a disallowed whitespace thing in their regular chat system to prevent things like this, check it out?

Simply make the chatting textbox’s MultiLine property unchecked.

It is unchecked, even textwrapped is unchecked.

1 Like

I FOUND THE ANSWER!
To anyone who had the problem like me:

Text = string.gsub(Text, "%s+", "")

That will remove all of the whitespaces (newlines and stuff) in the message.

1 Like

Can’t you just use something like

if string ~= "" then

or

local args = string.split(msg, " ")
local isntspam = false

for i,v in pairs(args) do
    if v ~= "" then
        isntspam = true
    end
end

Text:match("%s+", "")

Remember that string values are objects so you can call the string library functions on them as instance methods with the colon operator (personal preference).

For a more exact match you should make use of anchors which anchor the search pattern to the start/end of a string, those are “^” and “$”. Finally, replace the + modifier (1 or more occurrences) with the * modifier (0 or more occurrences).

Text:match("^%s*$", "")

This way a match only occurs if the subject string matches a search pattern which starts at the beginning of a string and is then followed by 0 or more occurrences of any whitespace character (as indicated by the %s character class) and then ends at the end of a string.