Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make a cooldown on my tool with debounce?

local mouse=game.Players.LocalPlayer:GetMouse() local fire = script.Parent:WaitForChild('fire') local debounce = true mouse.Button1Down:connect(function(key) fire:FireServer() wait(1) debounce = false

end)

this is my script but there is no cooldown

1 answer

✓ Accepted answer

Replace your script with the following:

local mouse=game.Players.LocalPlayer:GetMouse() 
local fire = script.Parent:WaitForChild('fire') 
local debounce = true 

mouse.Button1Down:connect(function(key)
	if debounce == true then
		debounce = false
		fire:FireServer() 
		wait(1)
		debounce = true
	end
end)

So what's wrong is that your script never checks if the debounce is true or false. So it just executes the code without cooldowns. The script I have given you will run the function only if debounce is true. As you can see, the debounce remains false for 1 second as a cooldown, and then turns true again.

1 comment

0

Thank you very much :)

This discussion is preserved as it was. New answers, comments, and votes are closed.