im working with UserInput Service and i have this code local UserInputService = game:GetService("UserInputService")

function onKeyPress(inputObject, gameProcessedEvent)
    print(inputObject.KeyCode)

    if script.Parent.Visible == true then
        if inputObject.KeyCode == Enum.KeyCode.E then
            print("E was Pressed!")
        end
    end
end


UserInputService.InputBegan:Connect(onKeyPress)

its not working no errors I've tested in both local and server scripts

6 comments

0

Where is the script located, and what type is it?

0

i forgot to move it to the gui but its in workspace<part<gui<localscript

0

but it should print what key is being pressed but it dosnt

1

LocalScripts are designed to operate in localized environments, workspace is global, therefore, the program will not run. UserInputService is only accessible from the Client. Using a ServerScript (designed to operate in global environments; research the Client-Server Model)

0

Will not respond to the logic either. To bring successful operation to your program, relocate the LocalScript appropriately. StarterPlayerScripts is a decent choice.

0

I also suggest you delve into Filtering Enabled.