Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Chatbar is not capturing focus. Why!? Everything seems right.

I seem to have everything down to the 'T' yet it is still not capturing focus of my keyboard but it's telling me on F9 that it's running!?

What gives? It should be as simple as the a, b, c's!

local StarterGui = game:GetService("StarterGui")
local Chat = game.StarterGui:WaitForChild("Chatbar");
local Input = Chat.Chatbar.Input;

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

function onKeyPress(actionName, userInputState, inputObject)
	if userInputState == Enum.UserInputState.Begin then
		print("The button / was pressed.");
		Input:CaptureFocus();
		print(Input:IsFocused());
	end
end

game.ContextActionService:BindAction("keyPress/", onKeyPress, false, "/");

I've included a free model to show you it in it's full form:

Here it is (the free model)

2 answers

You defined Chat as the ChatBar (TextBox), not Input. Plus, only TextBox objects can respond in :CaptureFocus().

Here. Let me fix the script for you!

local StarterGui = game:GetService("StarterGui")
local Chat = game.StarterGui:WaitForChild("Chatbar");
local Input = Chat.Chatbar.Input;

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

function onKeyPress(actionName, userInputState, inputObject)
    if userInputState == Enum.UserInputState.Begin then
        print("The button / was pressed.");
        Chat:CaptureFocus(); -- It should be Chat, not Input.
        print(Input:IsFocused());
    end
end

game.ContextActionService:BindAction("keyPress/", onKeyPress, false, "/");

Any questions? Leave a comment below, please. Thanks and I hope this will help you!

This discussion is preserved as it was. New answers, comments, and votes are closed.