PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

GetFocusedTextBox

The GetFocusedTextBox event returns an Instance of the TextBox currently selected by the player - such as when the player has selected a TextBox to input text.

Note: If the player has not selected a TextBox when this function is used, it will return nil.

Since UserInputService only runs client-side, this function will only work when used in a LocalScript.

Returns

Return Type Summary

The currently selected /TextBox, or nil if none is selected.


Code Samples


UserInputService:GetFocusedTextBox

This example prints the name of returned focused TextBox Instance, but only if a TextBox is focused. It checks for a focused TextBox every render step.

Note: It can be inefficient to check an event every render step. This example is meant only to show how GetFocusedTextBox can be used, and is not focused on efficiency or best use case.

local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

-- Get the Focused TextBox Instance
RunService.RenderStepped:Connect(function()
	local FocusedTextBox = UserInputService:GetFocusedTextBox()
	-- Print name of the focused TextBox
	if FocusedTextBox then
		print("Name of Focused TextBox is", FocusedTextBox.Name)
	end
end)