While loop with IsKeyDown debounce

  1. What do you want to achieve? Keep it simple and clear!
    How would I add a debounce to my script? I need to add it somehow so that it doesn’t stack my animation when the key E is pressed multiple times. I am also using decals on a part for the animation.

  2. What is the issue? Include screenshots / videos if possible!
    Normal:


    Stacked:

local Guy= game.Workspace.Animation

local StandingRight = Guy.Torso.D1
local SideRight = Guy.Torso.D2
local WalkingRight = Guy.Torso.D3
local WalkingRightV2 = Guy.Torso.D4

local StandingLeft = Guy.Torso.D01
local SideLeft = Guy.Torso.D02
local WalkingLeft = Guy.Torso.D03
local WalkingLeftV2 = Guy.Torso.D04

UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input)
	while UIS:IsKeyDown(Enum.KeyCode.E) do
		StandingLeft.Transparency = 1
		SideLeft.Transparency = 1
		WalkingLeft.Transparency = 1
		WalkingLeftV2.Transparency = 1
		StandingRight.Transparency = 1
		SideRight.Transparency = 0
		WalkingRight.Transparency = 1
		WalkingRightV2.Transparency = 1
		task.wait(1)

		SideRight.Transparency = 1
		WalkingRight.Transparency = 0
		WalkingRightV2.Transparency = 1
		task.wait(1)


		SideRight.Transparency = 0
		WalkingRight.Transparency = 1
		WalkingRightV2.Transparency = 1
		task.wait(1)

		SideRight.Transparency = 1
		WalkingRight.Transparency = 1
		WalkingRightV2.Transparency = 0
		task.wait(1)

	end
	end)

Replace the entire line

UIS.InputBegan:Connect(function(input)

with

task.spawn(function()

and remove the UIS:IsKeyDown(Enum.KeyCode.E) from the while loops definition. Put it inside the while loop as an if statement

These changes should work. I can elaboratr later

It works perfectly as you say, thank you for the help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.