I am trying to change the state of the debounce by clicking the shift key. I wrote this code but the if-then line isn't registering the change of state. Is there something wrong in my code or is there a technical thing I just don't know?
Here is my code:
local UserInputService = game:GetService("UserInputService") local debounce = false UserInputService.InputEnded:Connect(function(key) if key.KeyCode == Enum.KeyCode.LeftShift then debounce = false end end) UserInputService.InputBegan:Connect(function(key) if key.Keycode == Enum.KeyCode.LeftShift then debounce = true end end) if debounce == true then print ("1") end
Okay, so I think I see what the issue is. Your code works completely fine, but you're using the wrong type of script to be handling userinputservice. I recommended that you handle UserInputService with a local script under the "StarterPlayerScripts" folder nested under StarterPlayer. Player input should always be handled on the client side.
Also on line 11, you need to capitalize the c. You wrote Keycode, and not KeyCode.
if key.Keycode == Enum.KeyCode.LeftShift then