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

The debounce cant be included with toggle?

Hello, Im OriginalDevelops! Im trying to make a toggle with 2 attack sword that repeat and having a debounce, but the problem is the debounce, it didnt have any cooldown or debounce, anyways, the toggle still having a good work, this is my script, I hope someone can solve this for me with this!

local toggle = false
local animation2 = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Slash2)
local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Slash)

script.Parent.Equipped:Connect(function(Mouse)
    Mouse.Button1Down:Connect(function()
	if not toggle then
		toggle = false
        animation:Play()
        script.Parent.Handle.SwordSlash:Play()
        wait(1)
        toggle = true
		elseif toggle == true then
			toggle = true
        animation2:Play()
        script.Parent.Handle.SwordSlash:Play()
        wait(1)
        toggle = false
       end
    end)
end)

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

1 answer

✓ Accepted answer

Well a "debounce" doesn't specifically have to be "toggle" or "debounce". In your case, you want to have a debounce when a player equip a tool. So you can do:

local Equipped = false -- I changed from toggle to Equipped so it's not confusing.
local animation2 = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Slash2)
local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Slash)

script.Parent.Equipped:Connect(function(Mouse)
    Mouse.Button1Down:Connect(function()
    	if Equipped == false then -- by writing "not toggle" you are saying "not false" which is true and you should not do that.
        	Equipped = true
        	animation:Play()
        	script.Parent.Handle.SwordSlash:Play()
        	wait(1)
        	Equipped = false
        elseif Equipped == false then -- This is weird, why do you have 2 toggle == true? Including the one above. If you don't need you can just remove it.
            Equipped = true
        	animation2:Play()
        	script.Parent.Handle.SwordSlash:Play()
        	wait(1)
			Equipped = false
      	end
    end)
end)

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

NOTE: I noticed a problem here. Why did you write

script.Parent.Handle.SwordSlash:Play()

? Is that an animation? If yes then it's ok.

2 comments

0

Ahh, Im Not currently in studio but I will still accpect your answer, hope it works!

0

Well thanks, if it doesn't let me know

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