I’m making a reload function for a gun, when trying to check for the key pressed (which is R) the function does not run the code, the User input service does detect that the key has been pressed though.
The code I created is fairly simple.
UIS.InputBegan:Connect(function(keycode)
print("Key pressed")
if keycode == Enum.KeyCode.R then
--stuff
end
end)
Any sort of help would be appreciated.
1 Like
The InputBegan Event does not hand over the keycode, it hands over the input. Try this:
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
-- stuff
end
end)
If you dont really understand that yet, you should try printing the input.
1 Like
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input)
print("Clicked")
if input.KeyCode == Enum.KeyCode.R then
--stuff
print("R")
end
end)
1 Like