Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to check if a player is in a TextBox?

Asked by
ItsMeKlc 235 Moderation Voter
8 years ago

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

Log in to vote
1
Answered by 8 years ago

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

0
Looks good but isn't working for me.. Did I do something wrong? (I put it in the question) ItsMeKlc 235 — 8y
0
yes, i spelled stuff wrong, I'll edit ScriptsAhoy 202 — 8y
0
Ok, should work now ScriptsAhoy 202 — 8y
Ad

Answer this question