New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

InputBegan doesn't react to key press?

Asked by
NiKxzsu 13
1 year ago

This is a LocalScript in it. It won't print "react" or "works" when a key is pressed. Hovering my mouse for example does print "react". Pls help. script.Parent is a TextBox.

script.Parent.InputBegan:Connect(function(input)
    print("react")
    if input.UserInputType == Enum.UserInputType.Keyboard then
        print("works")
    end
end)

Thanks for helping.

0
Oops ignore the first sentence lol. NiKxzsu 13 — 1y

2 answers

Log in to vote
1
Answered by
royee354 129
1 year ago

Input began is the event of user input service you should've made a variable of the user input service and replace "script.Parent" in the first line with the variable, also make sure it's a local script because global scripts can't use the user input service.

0
Oh forgot about that you said it's a local script, oh well, if you didn't know that you can only use them in local scripts I guess it's useful lol. royee354 129 — 1y
0
It's also an event that TextBox has according to wiki: https://developer.roblox.com/api-reference/class/TextBox And yes I am using a LocalScript. NiKxzsu 13 — 1y
0
Oh that input began, royee354 129 — 1y
Ad
Log in to vote
0
Answered by 1 year ago

So here is what i did

script.Parent.InputBegan:Connect(function(input)

if input.UserInputType == Enum.UserInputType.Keyboard then

    local keyPressed = input.KeyCode

    print("A key is being pushed down! Key:",input.KeyCode)

end

end)

i used the following script with a little help from https://developer.roblox.com/api-reference/event/GuiObject/InputBegan

and then i hovered over the text box and started pressing buttons

..the outcome

!enter image description here

Answer this question