i have this it gives me no errors but it dosnt do what its supposed to
local UserInputService = game:GetService("UserInputService")
while wait(0.1) do
if script.Parent.Visible == true then
function onKeyPress(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.E then
print("R was Pressed!")
end
end
end
end
UserInputService.InputBegan:Connect(onKeyPress)

1 comment
It has to be Local Script to detect UserInputService signal and Local Script has to be in player locations like StarterPack, StarterGui, StarterCharacterScripts or StarterPlayerScripts. Obviously it will print "R was Pressed!" on local client, so to detect it on server you would have to use Remote Events.