This script is not working as it is supposed to

Hi out there, I am heroguy1134 and I am learning to script and I made a script in which the script is supposed to print "The player pressed the A key " when I press the A key but it ain’t working. Can anyone help me with this?

THE SCRIPT

UserInputService = game:GetService(“UserInputService”)

UserInputService.InputBegan:Connect (function(Input , gameProccesedEvent)
if Input.KeyCode == Enum.Keycode.A then
print (“The player pressed the A key”)
end
end)

Looks good, except you missed some capitalization in your condition statement.

Enum.keycode.A

should be

Enum.KeyCode.A

Any field is usually case-sensitive.

I am confused its written the exact same as you told and its still not working

You misspelled KeyCode.
You need to type in capitals

Is this a LocalScript somewhere in the client?

yes its there i placed it int he client

try changing UserInputService to a local variable?

Try this script

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(Key) 
    if Key.KeyCode == Enum.KeyCode.A then 
    print("Player pressed A")
    end
end)

Edit: You didn’t put userInputservice as a local variable.I think that is the error

its still not working please

30char

Type this code that I sent

its still not working

30character

Where exactly is the script located? Also double-check that it isn’t disabled.

Works as expected, must be some sort of developer error.

image

Which script are you using?
Local or server?

i am using local script

30char

It must be a LocalScript located in StarterPlayerScripts or StarterCharacterScripts. Just generally in Player.

Make sure it is there and try out @amalnk0007’s script. If you are still having issues, let us know.

1 Like

i tried out his script but it still aint working

Try restarting the Studio.That might be any studio error due to un - complete loading of the studio

@heroguy1134 it can also be in the Starter Gui

1 Like

okay then will try this too

30char

1 Like