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

How can I work a debounce into this script inorder to prevent spam?

I need a Debounce in this script to prevent it from being spammed.

I assume the Debounce needs to be placed within the part unlocked by the return, but I haven't been able to do it.

Putting it outside like normal makes the script stop functioning. Same as inside.

You can spam it easily, an infinitely.

With any debounce I have added, it's caused the script to stop working entirely. EDIT: IT IS SUPPOSED TO ACTIVATE A LEFTWARD DASHING MOTION ON DOUBLE TAP

work = false
tap = false
locplay = game.Players.LocalPlayer
human = locplay.Character.Humanoid
game:GetService("UserInputService").InputBegan:connect(function(input1)
    	if input1.KeyCode == Enum.KeyCode.A then
    	    if tap then
				print("blah")
			local anim = Instance.new("Animation",human)
				anim.AnimationId = "https://www.roblox.com/DashLEFT-item?id=454485046"
			local animtrack = human:LoadAnimation(anim)
				animtrack:Play()
				for i = 0,-2.5,-.5 do
					wait(.25)
				local Left = human.Parent.Torso.CFrame * CFrame.new(i,0,0)
					human.Parent.Torso.CFrame = Left
				end
				animtrack:Stop()
			return
			end
			tap = true
			wait(.4)
			tap = false
		else
	end
end)

1 answer

Gave it a shot - I essentially used tap as the debounce variable, let me know if this does what you need

work = false
tap = true
locplay = game.Players.LocalPlayer
human = locplay.Character.Humanoid
game:GetService("UserInputService").InputBegan:connect(function(input1)
        if input1.KeyCode == Enum.KeyCode.A then
            if tap then
				tap = false
                print("blah")
				local anim = Instance.new("Animation",human)
                anim.AnimationId = "https://www.roblox.com/DashLEFT-item?id=454485046"
           		local animtrack = human:LoadAnimation(anim)
                animtrack:Play()
                for i = 0,-2.5,-.5 do
                    wait(.25)
                local Left = human.Parent.Torso.CFrame * CFrame.new(i,0,0)
                    human.Parent.Torso.CFrame = Left
                end
                animtrack:Stop()

           		wait(.4)
            	tap = true
		end
    end
end)

1 comment

0

Thanks. You technically answered my question. Unfortunately, I neglected to put what my script was supposed to do. So you answer won't work as the script is supposed to be used on double tap.(Thus the return)

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