Enum.Keycode isn't doing anything in my LocalScript

Hello, I am trying to make a reloading event for my gun, but Enum.Keycode just isn’t working at all when I suppose it should work. There are no errors on the output. I legitimately have no clue about what is happening.
I have searched for similar threads and found many, but none solved my issue.
Here is part of the code I am using:

local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(input, gameProcessed)
	if input.UserInputType == Enum.UserInputType.MouseButton1 and Humanoid.Health >= 1 and Tool.Parent == Character and canfire then
		events.Firing:FireServer()
		print("shooting")
	elseif input.UserInputType == Enum.KeyCode.R and Humanoid.Health >= 1 and Tool.Parent == Character and canfire then
		events.Reload:FireServer()
		print("reloading!")
	end
end)

I hope this can be solved.

This is actually a very easy issue to fix.

Instead of going:

input.UserInputType -- only accepts Enum.UserInputType

you need to do

input.KeyCode -- does accept Enum.KeyCode

You are correct! The code now works as intended after fixing that small mistake. Thank you very much for pointing that out, I was popping a vein out of frustration.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.