Need help with debounces

I’m trying to add a cooldown for stealing in my basketball game, however I’m not quite sure why the debounces I added are not functional as the server still fires the remote allowing the animation to be spammed.

The reason I’m making a thread is because despite looking through the many threads available on Debounces, everything i tried simply wouldn’t produce a better outcome.

UIS.InputBegan:connect(function(input,gpe, IsTyping)
local StealDebounce = false
	if gpe then
		return
	end
		if not HasBall() then
			if input.KeyCode == Enum.KeyCode.R and Guarding == true and StealDebounce == false and not IsTyping then
			StealEvent:FireServer()
			StealDebounce = true
			wait(3)
			StealDebounce = false
		end
	end
end)

Thanks in advance!
-SpaceHex-

The reason your debounce isn’t working is because StealDebounce is within the event. Place it outside of the event.

You could also just add debounces on the server as exploiters can do almost anything locally.

With your current implementation, each time UserInputService.InputBegan fires, StealDebounce is set to false so it won’t work for what you’re trying to achieve, define it in the topmost scope.

Thank you very much, this worked!

I’ll try to shift things to the server side now, thank you!