Changing NPC walk speed while attacking

Im trying to set the NPC’s walkspeed to 0 when he does an attack animation so hes not moving and attacking at the same time. Im a little lost at the moment and cant seem to figure it out since im not familiar with the code.

local inAttackRange = (target.Position - script.Parent.HumanoidRootPart.Position).magnitude <= ATTACK_RANGE + 1

			if inAttackRange then
				CanAttack = true
				if not attacking and CanAttack then
					print("Attacking")
					CanAttack = false
					attacking = true
					if Combo == 1 then
						Attack1Anim:Play()
						Combo = 2
						DoingCombo = 1
						
						delay(0.8,function()
							if Combo == 2 then
								Combo = 1
							end
						end)
						
					elseif Combo == 2 then
						Attack2Anim:Play()
						Combo = 3
						DoingCombo = 2
						
						delay(0.8,function()
							if Combo == 3 then
								Combo = 1
							end
						end)
						
					elseif Combo == 3 then
						Attack3Anim:Play()
						Combo = 4
						DoingCombo = 3
						
						delay(0.8,function()
							if Combo == 4 then
								Combo = 1
							end
						end)
						
					elseif Combo == 4 then	
						Attack4Anim:Play()
						Combo = 1
						DoingCombo = 4
						
					end	

I could do this

Attack1Anim:Play()
Hum.Walkspeed = 0
Combo = 2
DoingCombo = 1

but then he doesnt move after the animation. Im not sure where in the code to set his walkspeed back to its original number.

1 Like

Hello AstroStudioz, you need to get his walk animation by a variable.

You need to create a while loop like “While PlayerIsWalking == true do” with inside the Walk:Play()

After the Attack animation, you add a wait() then you set the PlayerIsWalking to true, not forgetting his speed.
Or else, PlayerIsWalking to false.

Hopefully it’s usefull for you! (I’m not really good at explaining, sorry)