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

2 comments
You are using a local variable to define debounce. So, when you change it in their own functions, it doesn’t actually change it when you first define it. To the code, debounce doesn’t actually changed outside of the input functions, so it stays false
@DarkDanny That's wrong. He is declaring a local debounce within the script, so that debounce will be local to everything within that certain script, including it's functions. But if a local variable is declared within a function, that variable will only be usable in that function it was created in.