Force Player to Highlight Text

I was wondering if once the player focuses on a textbox you were able to highlight all the text currently in it? I read this post but I’m wondering if there’s a feature for that now:

It is currently not a feature. You have to double click on the text.

You can, use the TextBox’s SelectionStart property as well as the CursorPosition property and everything in between will be selected.

local textBox = script.Parent
textBox.Focused:Connect(function()
	textBox.SelectionStart = 1
	textBox.CursorPosition = textBox.Text:len() + 1
end)
2 Likes

This only works if they click on the right side, but not the left.

Hmm, I suggest making a custom handler for that then, text boxes are pretty buggy with inputs from what I’ve experienced so you might have to create your own handler, try something like this:

local textBox = script.Parent
local isDown = false
local timeOfFocus
textBox.Focused:Connect(function()
	isDown = true -- mouse button is down
	timeOfFocus = tick()
	textBox.SelectionStart = 1
	textBox.CursorPosition = textBox.Text:len() + 1
end)
textBox.InputEnded:Connect(function(input)
	if (input.UserInputType == Enum.UserInputType.Touch or input.UserInputType == Enum.UserInputType.MouseButton1) then 
		if isDown and tick() - timeOfFocus <= 0.5 then
			textBox.SelectionStart = 1
			textBox.CursorPosition = textBox.Text:len() + 1
		end
		isDown = false -- mouse button is no longer up
	end
end)

That doesn’t seem to do anything different than your first one.

local textbox = script.Parent
textbox.Focused:Connect(function()
	textbox.CursorPosition = #textbox.Text + 1
	textbox.SelectionStart = 1
end)

ClearTextOnFocus should be false ofc

3 Likes