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
Where is the script located, and what type is it?
i forgot to move it to the gui but its in workspace<part<gui<localscript
but it should print what key is being pressed but it dosnt
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)
Will not respond to the logic either. To bring successful operation to your program, relocate the LocalScript appropriately. StarterPlayerScripts is a decent choice.
I also suggest you delve into Filtering Enabled.