New lines on mobile in text boxes

I have a text box in my game that users are able to type in. Desktop users are able to create a new line in this text box by simply pressing the enter key, however on mobile pressing the enter key on their keyboards just makes them stop typing in the text box.

Is there a way to stop this and have the enter key on mobile also create a new line? Mobile users have a “Keyboard down” button anyway (on Apple Devices anyway, not sure about androids) or can just tap outside the text box.

1 Like

Haven’t tested it on mobile - try this as a local script & parent it to the textbox.


if ClearTextOnFocus is false

script.Parent.FocusLost:Connect(function(enter)
	if enter then
		script.Parent.Text ..= '\n'
		script.Parent:CaptureFocus()
	end
end)

if ClearTextOnFocus is true

script.Parent.FocusLost:Connect(function(enter)
	if enter then
		local input = script.Parent.Text
		script.Parent:CaptureFocus()
		script.Parent.Text = input..'\n'
		script.Parent.CursorPosition = script.Parent.Text:len()+1
	end
end)
2 Likes

Hey, thanks for your response.

I tested these on mobile and they didn’t work, it just closed the keyboard.

1 Like

I have found a solution based on what @DoorsPro_Bacon said above (New lines on mobile in text boxes - #2 by DoorsPro_Bacon)

Here is the code I used for reference, it is the exact same as what was provided but adding a task.wait(0.1) seems to allow for this to all work.

textBox.FocusLost:Connect(function(enter)
	if enter == true then
		textBox.Text ..= '\n'
		task.wait(0.1)
		textBox:CaptureFocus()
		return
	end
end)

Thanks @DoorsPro_Bacon for your response!

1 Like