TextBox Focus Help

Hi,

I’m currently trying to create a custom chat service for my game and there is a small bug that appears. I use the default keybind of “/” to force focus onto the chat TextBox which works well and the whole chat system is functional apart from one slightly annoying bug:

Because I’ve used the keybind “/” to force the player to chat, the text character appears in the TextBox as follows:

image

Here is the client source:

game:GetService("UserInputService").InputBegan:Connect(function(Input)
     if Input.KeyCode == Enum.KeyCode.Slash then
	if PlayerGui.Radio.State ~= "Off" then
	     PlayerGui.Radio.Frame.TextBox:CaptureFocus()
	end
     end
end)

Is there any way to stop the slash appearing after it’s focused? Any help would be appreciated,
Thanks -Tom :slight_smile:

1 Like

You can either clear the textbox or do Textbox.Text = Textbox.Text to not allow the slash to appear.

1 Like

That solution has been tried and it didn’t solve the problem, the slash still appears in front of the payload.

I came across this same issue a while ago, a good way to fix it would be to use

game:GetService("UserInputService").InputEnded:Connect(function(Input)

So it detects the keypress when the slash key is released.

You may also want to implement gameProcessedEvent so the text box code isn’t triggered if the user presses “/” while the text box is focused.

game:GetService("UserInputService").InputEnded:connect(function(inputObject, gameProcessedEvent)

	if gameProcessedEvent == false then

		if inputObject.KeyCode == Enum.KeyCode.Slash then
				if PlayerGui.Radio.State ~= "Off" then
	                PlayerGui.Radio.Frame.TextBox:CaptureFocus()
	            end
			end
		end

	end
end)
4 Likes

The GameProcessed parameter is already implemented, the code shown is an extract from a much larger script but thanks anyway :slight_smile:

The InputEnded does work now, I can’t believe I didn’t think of it :roll_eyes:
Thank you!

1 Like