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

How come the debounce in this script isnt working?

i have this script to make a animation play and the debounce in it isnt work as you can click again and restart the animation while its still playing

script.Parent.Equipped:Connect(function(Mouse)
    Mouse.Button1Down:Connect(function()
		local debounce = true
		if debounce == true then
			debounce = false
        animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
        animation:Play()
		wait(0.51)
		debounce = true
		end
    end)
end)

script.Parent.Unequipped:Connect(function()
        animation:Stop()
end)

2 answers

✓ Accepted answer

Try this script

local debounce = true
script.Parent.Equipped:Connect(function(Mouse)
    Mouse.Button1Down:Connect(function()
        if debounce == true then
            debounce = false
wait (1)
        animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
        animation:Play()
        wait(0.51)
        debounce = true
        end
    end)
end)

script.Parent.Unequipped:Connect(function()
        animation:Stop()
debounce = false
end)

Simply because you keep resetting it because you are defining it as true every time the mouse is clicked.

So I would put this following line before the script.Parent.Equipped line, and remove it from where it was previously

local debounce = true

Hope I helped, please let me know if you have any questions

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