How to detect when a new line is made on a TextBox?

I came up with a script to detect when new lines are made, however after a new line is made, i could not figure out how to make the script ignore it after the player types in more stuff:

script.Parent.TextBox:GetPropertyChangedSignal("Text"):Connect(function()
if string.find(script.Parent.Frame.ScrollingFrame.ScriptReader.Text,"\n") ~= nil then
print("NEW LINE")
end
end)

Any solutions on how to make this ignore lines after they have been made would be very appreciated!

1 Like

You can use text service to find the size of the text in pixels

Why not just turn off the MultiLine property of the textbox and listen to FocusLost instead?

local textbox = script.Parent.TextBox
textbox.FocusLost:Connect(function(e)
    if e then
        local textTheyTyped = textbox.Text
        --do whatever with it
        textbox:CaptureFocus() --if ClearTextOnFocus is false, set Text to "" beforehand
    end
end)
3 Likes

Combine some functions from UserInputService to achieve this

UserInputService.InputBegan:Connect(function(k)
   if k.KeyCode == Enum.KeyCode.Return then
      local textBox = UserInputService:GetFocusedTextBox()
      if textBox then
          --user pushed enter on a text box
      end
   end
end)
3 Likes