Pretty much the title, I’m looking to figure out when a new line in a text label is created (this is for a chat system)
I have tried checking the TextBounds, etc. but nothing seems to work.
Pretty much the title, I’m looking to figure out when a new line in a text label is created (this is for a chat system)
I have tried checking the TextBounds, etc. but nothing seems to work.
Have you tried using a string pattern that detects \n?
https://gfycat.com/ShorttermEqualFrigatebird
This is what I mean, a user never types \n and the Text property doesn’t hold \n in it.
What I would do is divide the TextBounds Y value by the font size, and then round that to the closest integer for your number of lines.
Perhaps I’m just not very good at UI designing, but I believe the text label needs to be larger in order for it to hold multiple lines…
^ This will only allow one line total.
^ This allows multiple.
Yes that is true. Resize it so that multiple lines can be displayed, and then dividing the text bound Y by the font size should give you the number of lines. To check when a new line is made, every time the text changes, compare the number of lines to the last known number of lines.
You can use TextBox:GetTextBounds()
to get the Text Size in Vector2 form.
It’ll also allow you to easily adjust the size, because you know how big the text is.
You know, you could’ve just looked in the text of the textlabel and looked for “\n” in the contents
local TextBox = --Textbox location
local newlines = 0
for i,v in pairs(TextBox.Text:split("")) do
if v == "\n" then
newlines += 1
end
end
print(newlines)