.Stopped;Wait()

Is it possible to disable movement with .stopped:wait()?

Basically i need my npc to stop chasing me while hes in a attack animation.

An animation stopped event is fired when the animation stops.

You could just set the NPC’s walkspeed to 0 too.

humanoid.WalkSpeed = 0

If you need to stop the animation call the Stop() function.
AnimationTrack:Stop() -- something like this

More info here:
https://developer.roblox.com/en-us/api-reference/function/AnimationTrack/Stop

I tried setting the walkspeed to 0 but got nothing. i will give the link a read and see what i can come up with

anchor the HumanoidRootPart, works for me

how would i go about doing that?

Depending on how you made the chasing portion, everytime the NPC enters the attack mode, you can break or yield whatever code you have that handles the movement.

HumanoidRootPart.Anchored = true

Here is the script. ive tried setting the position as well as humanoid walk speed but cant seem to get it.

local ATTACK_RANGE = 2.5
local CanAttack = false
local attacking = false
local Combo = 1
local DoingCombo = 0

local Hum = script.Parent:WaitForChild(“Humanoid”)
local FX = script:WaitForChild(“FX”)
local TweenService = game:GetService(“TweenService”)

local Anims = script.Parent:WaitForChild(“Anims”)
local Attack1Anim = Hum:LoadAnimation(Anims:WaitForChild(“Attack1”))
local Attack2Anim = Hum:LoadAnimation(Anims:WaitForChild(“Attack2”))
local Attack3Anim = Hum:LoadAnimation(Anims:WaitForChild(“Attack3”))
local Attack4Anim = Hum:LoadAnimation(Anims:WaitForChild(“Attack4”))

local HiteffectBall = function(Target,Pos)
local ClonedBall = FX.Thing:Clone()
ClonedBall.Parent = Target
ClonedBall.CFrame = Pos
ClonedBall.CFrame = CFrame.new(ClonedBall.Position, Target.Position)
ClonedBall.Transparency = 0
game.Debris:AddItem(ClonedBall,1)

if DoingCombo == 4 then
	ClonedBall.BrickColor = BrickColor.new("Neon orange")
end

TweenService:Create(ClonedBall,TweenInfo.new(0.5,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut),{CFrame = ClonedBall.CFrame + ClonedBall.CFrame.lookVector * -7,Transparency = 1,Size = Vector3.new(0.087, 0.08, 3.35)}):Play()

end

local InsertDisabled = function(Target,Time)
local Disabled = Instance.new(“BoolValue”,Target)
Disabled.Name = “Disabled”
game.Debris:AddItem(Disabled,Time)
end

local target = nil

local function runToTarget()
local targetPosition = (script.Parent.HumanoidRootPart.Position - target.Position).Unit * (ATTACK_RANGE - 1) + target.Position

script.Parent.Humanoid:MoveTo(targetPosition)

end

function findTargets()
local list = game.Workspace:GetChildren()
local torso = nil
local dist = 25
local temp = nil
local human = nil
local temp2 = nil
for x = 1, #list do
temp2 = list[x]
if (temp2.className == “Model”) and (temp2 ~= script.Parent) then
temp = temp2:findFirstChild(“HumanoidRootPart”)
human = temp2:findFirstChild(“Humanoid”)
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) and game.Players:FindFirstChild(temp2.Name) then
if (temp.Position - script.Parent.HumanoidRootPart.Position).magnitude < dist then
torso = temp
dist = (temp.Position - script.Parent.HumanoidRootPart.Position).magnitude
target = torso.Parent.HumanoidRootPart
else
target = nil
end
end
end
end
end

local function onHeartbeat()

if target and script.Parent:FindFirstChild("Disabled") == nil then
	if target.Parent.Humanoid.Health <= 0 then
		target = nil
	else
		
		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	
				
				target.Parent.Humanoid.WalkSpeed = 1
				target.Parent.Humanoid.JumpPower = 0
				
				delay(0.72,function()
					if target ~= nil and target.Parent:FindFirstChild("Disabled") == nil then
						target.Parent.Humanoid.WalkSpeed = 16
						target.Parent.Humanoid.JumpPower = 50
					end	
				end)
				
				delay(0.12,function()
					if script.Parent:FindFirstChild("Disabled") == nil then
						if DoingCombo == 1 then
							target.Parent.Humanoid:TakeDamage(8)
						elseif DoingCombo == 2 then
							target.Parent.Humanoid:TakeDamage(8)
						elseif DoingCombo == 3 then
							target.Parent.Humanoid:TakeDamage(8)
						elseif DoingCombo == 4 then	
							target.Parent.Humanoid:TakeDamage(12)
							
							local Pos = script.Parent.HumanoidRootPart.CFrame*CFrame.new(0,0,-26)

							local BP = Instance.new("BodyPosition",target)
							BP.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
							BP.D = 90
							BP.P = 400
							BP.Position = Pos.p
							game.Debris:AddItem(BP,0.4)
						end	
						
						local Count = 0
						repeat
							Count = Count + 1
							HiteffectBall(target,target.CFrame * CFrame.new(math.random(-1,1),math.random(-1,1),math.random(-1,1)))
						until Count >= 5
						
						InsertDisabled(target.Parent,.55)
					end
				end)
				
				delay(0.6,function()
					attacking = false					
				end)
			end
		else
			runToTarget()
		end
	end	
end

-- Check if the current target no longer exists or is not attackable
if target == nil then
	findTargets()
end

end

local RunService = game:GetService(“RunService”)

RunService.Heartbeat:Connect(function()
onHeartbeat()
end)

Hum.Died:Connect(function()
script.Parent.Health:Destroy()
script.Parent.Head.BillboardGui:Destroy()
script.Parent.Healthandstuff:Destroy()

for i,v in pairs(script.Parent:GetChildren()) do
	if v:IsA("Part") or v:IsA("MeshPart") then
		local TweenService = game:GetService("TweenService")
		
		local Tweeninf = TweenInfo.new(0.6)
		
		v.Anchored = true
		
		local DecayFX = FX.DecayFX:Clone()
		DecayFX.Parent = v
		DecayFX:Emit(70)
		
		local Tween = TweenService:Create(v,Tweeninf,{Transparency = 1})
		Tween:Play()
	end
end

script:Destroy()

end)

local ATTACK_RANGE = 2.5
local CanAttack = false
local attacking = false
local Combo = 1
local DoingCombo = 0

local Hum = script.Parent:WaitForChild("Humanoid")
local FX = script:WaitForChild("FX")
local TweenService = game:GetService("TweenService")

local Anims = script.Parent:WaitForChild("Anims")
local Attack1Anim = Hum:LoadAnimation(Anims:WaitForChild("Attack1"))
local Attack2Anim = Hum:LoadAnimation(Anims:WaitForChild("Attack2"))
local Attack3Anim = Hum:LoadAnimation(Anims:WaitForChild("Attack3"))
local Attack4Anim = Hum:LoadAnimation(Anims:WaitForChild("Attack4"))

local HiteffectBall = function(Target,Pos)
	local ClonedBall = FX.Thing:Clone()
	ClonedBall.Parent = Target
	ClonedBall.CFrame = Pos
	ClonedBall.CFrame = CFrame.new(ClonedBall.Position, Target.Position)
	ClonedBall.Transparency = 0
	game.Debris:AddItem(ClonedBall,1)

	if DoingCombo == 4 then
		ClonedBall.BrickColor = BrickColor.new("Neon orange")
	end

	TweenService:Create(ClonedBall,TweenInfo.new(0.5,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut),{CFrame = ClonedBall.CFrame + ClonedBall.CFrame.lookVector * -7,Transparency = 1,Size = Vector3.new(0.087, 0.08, 3.35)}):Play()
end

local InsertDisabled = function(Target,Time)
	local Disabled = Instance.new("BoolValue",Target)
	Disabled.Name = "Disabled"
	game.Debris:AddItem(Disabled,Time)
end	

local target = nil

local function runToTarget()
	local targetPosition = (script.Parent.HumanoidRootPart.Position - target.Position).Unit * (ATTACK_RANGE - 1) + target.Position

	script.Parent.Humanoid:MoveTo(targetPosition)
end

function findTargets()
	local list = game.Workspace:GetChildren()
	local torso = nil
	local dist = 25
	local temp = nil
	local human = nil
	local temp2 = nil
	for x = 1, #list do
		temp2 = list[x]
		if (temp2.className == "Model") and (temp2 ~= script.Parent) then
			temp = temp2:findFirstChild("HumanoidRootPart")
			human = temp2:findFirstChild("Humanoid")
			if (temp ~= nil) and (human ~= nil) and (human.Health > 0) and game.Players:FindFirstChild(temp2.Name) then
				if (temp.Position - script.Parent.HumanoidRootPart.Position).magnitude < dist then
					torso = temp
					dist = (temp.Position - script.Parent.HumanoidRootPart.Position).magnitude
					target = torso.Parent.HumanoidRootPart
				else
					target = nil
				end
			end
		end
	end
end


local function onHeartbeat()
	
	if target and script.Parent:FindFirstChild("Disabled") == nil then
		if target.Parent.Humanoid.Health <= 0 then
			target = nil
		else
			
			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	
					
					target.Parent.Humanoid.WalkSpeed = 1
					target.Parent.Humanoid.JumpPower = 0
					
					delay(0.72,function()
						if target ~= nil and target.Parent:FindFirstChild("Disabled") == nil then
							target.Parent.Humanoid.WalkSpeed = 16
							target.Parent.Humanoid.JumpPower = 50
						end	
					end)
					
					delay(0.12,function()
						if script.Parent:FindFirstChild("Disabled") == nil then
							if DoingCombo == 1 then
								target.Parent.Humanoid:TakeDamage(8)
							elseif DoingCombo == 2 then
								target.Parent.Humanoid:TakeDamage(8)
							elseif DoingCombo == 3 then
								target.Parent.Humanoid:TakeDamage(8)
							elseif DoingCombo == 4 then	
								target.Parent.Humanoid:TakeDamage(12)
								
								local Pos = script.Parent.HumanoidRootPart.CFrame*CFrame.new(0,0,-26)

								local BP = Instance.new("BodyPosition",target)
								BP.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
								BP.D = 90
								BP.P = 400
								BP.Position = Pos.p
								game.Debris:AddItem(BP,0.4)
							end	
							
							local Count = 0
							repeat
								Count = Count + 1
								HiteffectBall(target,target.CFrame * CFrame.new(math.random(-1,1),math.random(-1,1),math.random(-1,1)))
							until Count >= 5
							
							InsertDisabled(target.Parent,.55)
						end
					end)
					
					delay(0.6,function()
						attacking = false					
					end)
				end
			else
				runToTarget()
			end
		end	
	end

	-- Check if the current target no longer exists or is not attackable
	if target == nil then
		findTargets()
	end
end

local RunService = game:GetService("RunService")

RunService.Heartbeat:Connect(function()
	onHeartbeat()
end)

Hum.Died:Connect(function()
	script.Parent.Health:Destroy()
	script.Parent.Head.BillboardGui:Destroy()
	script.Parent.Healthandstuff:Destroy()
	
	for i,v in pairs(script.Parent:GetChildren()) do
		if v:IsA("Part") or v:IsA("MeshPart") then
			local TweenService = game:GetService("TweenService")
			
			local Tweeninf = TweenInfo.new(0.6)
			
			v.Anchored = true
			
			local DecayFX = FX.DecayFX:Clone()
			DecayFX.Parent = v
			DecayFX:Emit(70)
			
			local Tween = TweenService:Create(v,Tweeninf,{Transparency = 1})
			Tween:Play()
		end
	end
	
	script:Destroy()
end)

What could be happening is when it’s attacking, the player moves out of range causing it to move mid-attack. Try making that if inAttackRange and not attacking then and see if that fixes it.

That didn’t seem to work. I’ve tried a few things and cant seem to get it to work.

Do you have a video of the NPC’s behavior?

Yeah i can make one. give me about 15 minutes.

You can check if the AnimationTrack is playing by using IsPlaying (AnimationTrack | Roblox Creator Documentation)

ezgif.com-gif-maker

You can cancel the AnimationTrack with AnimationTrack:Stop().

You can cancel Humanoid:MoveTo by either:

  • Setting Humanoid.WalkToPoint and Humanoid.WalkToPart to nil (might need an actual value, if so try the next solution)
  • Calling Humanoid:MoveTo with the Humanoid’s position (might cause the Humanoid to turn, I’d recommend trying the previous solution first)

(You’ll probably want to call your WalkToTarget function again after canceling the Humanoid:MoveTo call)