In my custom Chat GUI the Text Box in which the user will type whatever he/she wants to chat. I want to focus the text box when a key is pressed, but it says that Focused is not a valid member of TextBox. Please tell me how I can fix this.
Here is the script:
local userInput = game:GetService("UserInputService") local function inputBegan(input, gameProcessed) if input.UserInputType == Enum.UserInputType.Keyboard then local key = input.KeyCode if key == Enum.KeyCode.Slash or key == Enum.KeyCode.BackSlash then script.Parent.Focused = true end end end userInput.InputBegan:Connect(inputBegan)
Thanks!
its because Focused
isnt a property of TextBox which you should probably know because the error says it. so instead just use :CaptureFocus()
which forces the client to focus on the textbox.
local userInput = game:GetService("UserInputService") local function inputBegan(input, gameProcessed) if input.UserInputType == Enum.UserInputType.Keyboard then local key = input.KeyCode if key == Enum.KeyCode.Slash or key == Enum.KeyCode.BackSlash then script.Parent:CaptureFocus() end end end userInput.InputBegan:Connect(inputBegan)