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

On tool.Activated, debounce cooldown will not work?

The LocalScript is inside a tool. It is supposed to choose a random animation and play it. The random and animations work but the cooldown i applied doesnt seem to work. Any Help? Here's what you need to see:

debounce = false
 

	
tool.Activated:Connect(function()
	
if debounce == false then	
	debounce = true
	
 local attack1 = hum:LoadAnimation(script.Animation1)
local attack2 = hum:LoadAnimation(script.Animation2)

local chooseattack = math.random(1,3)

if chooseattack == 1 then
	
   attack1:Play()
	
end

if chooseattack == 2 then

   attack2:Play()
	
end

wait(1)
debounce = false
end

end)

2 comments

0

I dunno since you didn't indent correctly, man.

0

sorry im still learning to script so i dont really know how to indent right, are you sure you dont have a sliver of a thought, how to help me?

1 answer

✓ Accepted answer

I not that sure if this will work but try it

debounce = false

tool = script.Parent --you hadnt set this to anything
hum = game:GetService("Players").LocalPlayer.Character.Humanoid -- you hadnt set this either


		
local anims = {script.Animation1,script.Animation2}--stores the animations in an array
		
 -- gets a random number from 1 to 2
	
tool.Activated:Connect(function()
	if not debounce then   -- if debounce is false
		debounce = true --sets it to true
		local chooseattack = math.random(2)
		local animation = hum:LoadAnimation(anims[chooseattack]) --this will load a random animation, from the array, into the player
		animation:Play() -- plays it
		wait(1)--waits 1
		debounce = false--sets debounce to false
	end

end)


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