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

InputBegan doesn't react to key press?

Asked by
NiKxzsu 13
4 years 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 — 4y

2 answers

Log in to vote
1
Answered by
royee354 129
4 years 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 — 4y
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 — 4y
0
Oh that input began, royee354 129 — 4y
Ad
Log in to vote
0
Answered by 4 years 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