TextBox working weird?

Whenever i clear my text in my textbox and write something new in it this happens:
image
and therefor i cannot detect if a player sends a correct command but it dosen’t detect it? The only way i managed to get around this is to delete one character off and it works regular?

1 Like

Could you please provide more detailed information than a debug console screenshot that is not explained in any way?

Would you mind showing a script.

So basically every time I enter a command in the ui it should clear it and then auto focus on it. But I’ll provide a script soon

Basically this is for a command prompt in roblox which checks when a player pressed enter. now I also use a custom font for the text box and the other text labels i have.

textBox.FocusLost:Connect(function(enter,InputObject)
  if enter and textBox.Text ~= "" and textBox.Text ~= " " then
	local text = textBox.Text
	
	local split = text:split(" ")
	
	local cmdName = split[1]
	cmdName = cmdName:lower()
	
	print(cmdName)
	
	if commands[cmdName] then
		local arguments = {}
		
		for i = 2,#split,1 do
			table.insert(arguments,split[i])
		end
		
		commands[cmdName](text,arguments)
		textBox.Text = ""
		textBox:CaptureFocus()
		
	else
		createNewOutput(text,"Error 1: Invalid Command")
		textBox.Text = ""
		textBox:CaptureFocus()

	end
  end
 end)

image

1 Like

What exactly is the error again? And no need to force CaptureFocus

I figured it out somehow it worked by putting the capturefocus in a spawn function. but yeah

1 Like

So the code runs fine now?

This text will be blurred

1 Like

Yeah it works completely fine now!

Well, mark anything as a solution or delete the thread.

The proper fix is to add a minor yield before calling CaptureFocus on the text box instance.

--'E' key is pressed.
task.wait() --Minor yield.
TextBox:CaptureFocus() --Focus the text box.
1 Like

THANK YOU! i was using

TextBox:CaptureFocus()
task.wait(0)
TextBox.Text = ""

before and it cleared all my text