How do I fix my debounce?

I’m trying to add a debounce to my fireball with a number value. When it turns 0 you should be able to fire the event which fires the fireball. But, for some reason it’s not working. Any idea what could be wrong?
Script:

local Debounce = script:WaitForChild("CoolDownValue")

Debounce = math.clamp(Debounce.Value,0,10)

while wait(1) do

Debounce -= 1

end
--User input
if Debounce == 0 then
		Event:FireServer(mouse.hit.p)
			wait(0.01)
		Debounce = 10

Thanks for reading.

Is this script sending any errors?

This May be the issue so i would fix that and if i’m wrong just reply to me.

Sorry for bad format, I’m on mobile. I would just do this though.

local waitTime = script:WaitForChild(“CoolDownValue”).Value
local debounce = false

if debounce == false then
debounce = true
Event:FireServer(mouse.hit.p)
wait(waitTime)
debounce = false
end

1 Like

What should I do??? Because it’s already like that.

There is no script errors I will try using prints though right now.

You should use the method that @24Nick_42 used its better and easier

This would work, but I kind of want a gui that shows how much more they have to wait.

Try this:

local Debounce = script:WaitForChild("CoolDownValue")
Debounce = math.clamp(Debounce.Value,0,10)

for i = Debounce,0,-1  do
	Debounce = i
	wait(1)
end

--User input
Event:FireServer(mouse.hit.p)
wait(0.01)
Debounce = 10

You can put the texlabel or whatever you use to measure how much is left in the loop.

Did you forget a .Value after the WaitForChild? Also, if you’re just setting the Debounce to 10 later on you should just do that in the first place.

It doesn’t change the debounce to 10 I think the wait(1) isn’t working.

Ok I will try this method that you insisted on.

Ah simple i did this before so When you fire back to client for a cooldown you can just have tween start for a gui

1 Like

In your script you Debounce = 10, which is setting it to 10.

if Debounce == 0 then
Event:FireServer(mouse.hit.p)
wait(0.01)
Debounce = 10
end

I think I know this already. What are you trying to say?

local Debounce = script:WaitForChild("CoolDownValue") is useless. Just use local Debounce = 10

1 Like