Cannot use :CaptureFocus() on a TextBox that is reserved

Basically, I’m using a custom textbox for chat, and I set the playergui to use that textbox, and it works! The problem is that even though KeyboardKeyCode is setup and enabled, it won’t detect when I press /, and the textbox doesn’t focus.

tl;dr: textbox doesnt focus when pressing / like in roblox chat

I tried using :CaptureFocus() but I got an error saying im trying to do it on a reserved textbox for chat, and I couldn’t.

Any ideas on how I can fix this?


I don’t know if this is what you are trying to do. But I just used UserInputService.InputBegan and it detects Slash. Make sure you don’t return if gameProcessedEvent as lots of scripts do.

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(input: InputObject, gameProcessedEvent: boolean)
	if input.KeyCode == Enum.KeyCode.Slash then
		print("Slash pressed")
	end
end)

I have a custom textbox for chat (using Roblox’s chat scripts), and slash to chat should be enabled, but it won’t detect it.

I also tried using UserInputService but it returned an error saying I can’t manually focus the textbox.

Roblox made a post reply regarding this, stating that the hotkey should work as intended, but it isn’t for me. Chat works though.

Result from trying to :CaptureFocus() manually on the textbox object
Screenshot 2024-01-28 at 11.18.34 AM

:CaptureFocus() seems to be working for me

local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local StarterGui = game:GetService("StarterGui")

local player = Players.LocalPlayer
local playerGui = player.PlayerGui

local screenGui = playerGui:WaitForChild("ScreenGui")
local textBox = screenGui:WaitForChild("TextBox")

StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, false)

UserInputService.InputBegan:Connect(function(input: InputObject, gameProcessedEvent: boolean)
	if input.KeyCode == Enum.KeyCode.Slash then
		StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, false)
		print("Slash pressed")
		if textBox.PlaceholderText == " " then
			print("toggled off")
			textBox.Text = ""
			textBox.PlaceholderText = "To chat, click here or press / key"
			textBox:ReleaseFocus()
		else
			print("toggled on")
			textBox.PlaceholderText = " "
			task.spawn(function()
				for i = 0, 10 do
					textBox.Text = ""
					task.wait()
				end
			end)
			textBox:CaptureFocus()
			textBox.FocusLost:Once(function()
				textBox.Text = ""
				textBox.PlaceholderText = "To chat, click here or press / key"
			end)
		end
	end
end)

Is that a fully custom chat system that you scripted, or is the Textbox configured to ChatInputBarConfiguration.Textbox and using Roblox’s chat system?

It’s a regular TextBox, if you want to create a custom chat system. Why don’t you not use the ChatInput stuff and just do it manually like with RemoteEvents

Video demonstration of what I’m experiencing. Using a custom textbox for chat with Roblox’s chat scripts.

That’s not allowed because of Roblox’s security features. If you were able to:

then it would be a huge vulnerability for players as you could send any message on their behalf and get them banned. The solution to this is to not use ChatInputBarConfiguration as it’s .TextBox property has not been fully implemented yet and create your own chat system using remote events and TextChannel:SendAsync()

Moreover, it’s supposed to do this but the staff team messed up and forgot about it.

1 Like

Same with me. ‘Slash’ does not work.