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

How to check if a player is in a TextBox?

How do you check if a player is typing in a TextBox? I have certain keys bind to open menus in my game and this is an issue for when I need the player typing in a TextBox.

EDIT; This is what I currently have, but it doesn't work...

userInput = game:GetService("UserInputService")

focused = false
userInput.TextBoxFoxused:connect(function()--fires when the player focuses on a textBox
    focused = true
	print("We live!")
end)

userInput.TextBoxFoxusedReleased:connect(function()--fires when the player unfocuses from a textBox
    focused = false
	print("We off")
end)
userInput.InputBegan:connect(function(input)
	print("Hi!")
	if input.UserInputType == Enum.UserInputType.Keyboard and input.UserInputState == Enum.UserInputState.Begin and input.KeyCode == Enum.KeyCode.M and focused == false then

		onClicked()
	
	end
end)
script.Parent.MouseButton1Click:connect(onClicked)

1 answer

✓ Accepted answer

With this!

uis = game:GetService("UserInputService")
focused = false
uis.TextBoxFocused:connect(function()--fires when the player focuses on a textBox
	focused = true
end)

uis.TextBoxFocusReleased:connect(function()--fires when the player unfocuses from a textBox
	focused = false
end)

Then just add an if not focused then do all the stuff with the keys pressed.

#Credit to M39a9am3R for this one

3 comments

0

Looks good but isn't working for me.. Did I do something wrong? (I put it in the question)

0

yes, i spelled stuff wrong, I'll edit

0

Ok, should work now

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