Debounce not working over activated event

I’m trying to make an Ability system that will be activated if you toggle the ability button. The issue here is Debounce is not working and you can just spam the ability without delay.

Code:

script.Parent.BillboardGui.Frame.Abilities.Ability.Activated:Connect(function()
	local Debounce = false
	if Debounce == false then
		Debounce = true
		print("Triggered Ability")
		local abilityFunc = AbilityTowerFunc:InvokeServer(selectedTower)
		task.wait(2)
		Debounce = false
	end
end)

In the function supplied to connect, you are initializing Debounce to false at the start each time. This means in every scenario debounce will always be false whenever ability is activated. Move your decleration of Debounce outside of the function, just above.

local Debounce = false

script.Parent.BillboardGui.Frame.Abilities.Ability.Activated:Connect(function()
	if not Debounce then
		Debounce = true

		print("Triggered Ability")
		local abilityFunc = AbilityTowerFunc:InvokeServer(selectedTower)
		task.wait(2)

		Debounce = false
	end
end)
1 Like

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