Textbox Unfocues when I press return

Okay so, I’m trying to do something similar to the chat where when you press return, the message gets sent, right? However, when I do that, the TextBox unfocuses even though I have an if statement that checks whether that textbox is focused. Is there any way to fix this?

User input code:

UIS.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.Return and TextBox:IsFocused() then
		sendMsg()
	end
end)

I can not help you unless you send code and screenshots.
If you are scripting this, you should put this in #help-and-feedback:scripting-support

Hello,
i understand the problem, But can you send in code

Does this help

There is a property inside of the TextBox called ClearTextOnFocus, try turning that on/off and try testing your results. Also, I’m 75% this doesn’t have to do with the code. I assume your code is working fine, checking the textbox text correctly, but when this property is changed, the text doesn’t clear when the textbox isn’t in focus.

This isn’t exactly related to code, it’s related to a UI element.

I’ve already turned this property off. There were no changes.

Have you considered using the FocusLost event of text boxes?

Thanks man! That worked. :heart:

1 Like