Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Userinput service is not working. Help???

local inputServe = game:GetService("UserInputService")
inputServe.InputBegan:Connect(function(input, gameProccesedEvent)
	if input.KeyCode == Enum.KeyCode.G then
		print("G pressed.")
	end
end)

There is no errors that happened. It's in a local script, and its in starterplayerscripts

5 comments

0

I actually copied your original code and it worked just fine, perhaps there's something else wrong with your code?

0

This is not really an endearing question..

0

Things to check: Is script disabled? Is there inf loop before this code (common mistake)? Is this function firing at all (put print before if statement)? Is your keyboard working properly?

0

what happened here

0

erease ", gameProccessedEvent" and it will work

4 answers

Hi, try changing 'input' in your function parameters to something else, like this

local inputServe = game:GetService("UserInputService")
inputServe.InputBegan:Connect(function(inputKey, gameProccesedEvent)
    if inputKey.KeyCode == Enum.KeyCode.G then
        print("G pressed.")
    end
end)

4 comments

1

I dont wanna sound toxic, but the parameters are not the issue here.

1

It fixed my issue at one point, not sure if it was just a loose variable that it was taking or what.

0

Well its a different case for every script cause every script works in a different way, depending on how you scripted it.

1

InputObject & GameProcessedInput are the most appropriate parameter names.

Unless there is something else in your script this should be working.

game:GetService("UserInputService").InputBegan:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.G then
		print("G Pressed.")
	end
end)

Add a LocalScript to StarterGui and type this:

local Service = game:GetService("UserInputService")
Input.InputBegan:Connect(function(Input)
    if Input.KeyCode == Enum.KeyCode.G then
        print("G was pressed")
    end
end)

I Had This Error Too, First It Has To be In A Local Script And Try To Put The Local Script In The Backpack

This discussion is preserved as it was. New answers, comments, and votes are closed.