How can i detect selection word in textbox

how can I detect a word when it selects a word on textbox like this how can I detect “00”?
image

What solutions have you tried so far? I searched but couldn’t find anything

Put a local script inside the text box.

script.Parent.Changed:Connect(function()
if script.Parent.Text == 00 then
-- Do whatever you want --
end
end)

i know i want when it select word by this blue thing it detect

When the player presses the button?

no when select unique word in textbox like in photo

image
like in this photo i select only “extbox” how can i detect it in textbox

You would want to use the SelectionStart property in conjunction with the CursorPosition property, both of which are pretty self-explanatory. If you want to get the current selection, you can use this function:

function getSelectedText(textBox)
	if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then return end

	local selectedText = string.sub(
		textBox.Text,
		math.min(textBox.CursorPosition, textBox.SelectionStart),
		math.max(textBox.CursorPosition, textBox.SelectionStart)
	)

	return selectedText
end
2 Likes

thx this is the solution of my probloem :slight_smile: