Is there a way to stop a animation when a part is touched for a npc? [SOLVED]

So, I have a script where when an npc touched a part then it will stop a animation. But, when I put a part.touched event then the animation doesn’t play at all in this script I got rit of the touched event btw

local PathFindingService = game:GetService(“PathfindingService”)

local npc = script.Parent
local humanoid = npc:WaitForChild(“Humanoid”)
local GoalPart = game.Workspace:WaitForChild(“GoalPart”)

local path = PathFindingService:CreatePath({
AgentCanJump = true,
AgentCanClimb = true,
})

local success, errorMessage = pcall(function()
path:ComputeAsync(npc.PrimaryPart.Position, GoalPart.Position)
local animation = script:WaitForChild(“Walk”)
local npc = script.Parent:WaitForChild(“Humanoid”)
local model = npc:LoadAnimation(animation)
local goalPart = game.Workspace:WaitForChild(“GoalPart”)
model:Play()
end)

if success then
for _,waypoint in pairs(path:GetWaypoints()) do
local part = Instance.new(“Part”)
part.Material = “Neon”
part.Anchored = true
part.CanCollide = false
part.Shape = “Ball”
part.Position = waypoint.Position
part.Parent = game.Workspace

	humanoid:MoveTo(waypoint.Position)
	humanoid.MoveToFinished:Wait()

	if waypoint.Action == Enum.PathWaypointAction.Jump then
		humanoid.Jump = true
	end
		end

else
warn(“The path has not worked”, errorMessage)
end

1 Like

just do model:Stop()
Char limit

What is a char limit? also when I made the original script I did use model:stop but the animation wouldn’t play at all

He just typed in “Char limit” because devforum requires a character limit for replies.

Also, I’m not entirely sure why you’re using a part’s Touched event to know when to play an animation. I’m assuming the part you’re using is the ball you create at the waypoint location, but a better way to handle it is to use the Humanoid.MoveToFinished event. Also, I’d make sure that the animation you want to play has the priority set properly so it can play over the walk and idle animations.

So, I tried to use Humanoid.MoveToFinished but when I use this the animation it was doing the same thing and it was not stopping

	humanoid.MoveToFinished:Connect(function()
		model:Stop()
	end)

So I found the solution myself I detected if the move was finished with a if statement and if it was at the correct point then the animation would stop

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