Attempt to index nil with 'keycode'

So I made a local script where you press f for a gui to pop up but it keeps giving me the error “attempt to index nil with keycode”

local uis = game:GetService("UserInputService")
local debounce = false

local function onInputBegan(input, gameProcessed)
	if input.KeyCode == Enum.KeyCode.F then
		if debounce == false then
			script.Parent.Enabled = true
			debounce = true
		else
			script.Parent.Enabled = false
			debounce = false
		end
	end
end

uis.InputBegan:Connect(function()
	if game.ReplicatedStorage.InMenu.Value == false then
		onInputBegan()
	end
end)

You are not passing the parameters of InputBegan as the arguments for onInputBegan(). You should say:

uis.InputBegan:Connect(function(input, gameProcessed)
	if game.ReplicatedStorage.InMenu.Value == false then
		onInputBegan(input, gameProcessed)
	end
end)
4 Likes