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:
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.