local Humanoid = script.Parent:WaitForChild("Humanoid") local Torso = script.Parent:WaitForChild("Torso") local Animation = Instance.new("Animation") Animation.AnimationId = "http://www.roblox.com/asset/?id=180426354" local LoadedAnimation = Humanoid:LoadAnimation(Animation) while true do local targetName = script.Parent:WaitForChild("Target") local PathService = game:GetService("PathfindingService") local Target = workspace:WaitForChild(targetName.Value) local StartPos = Torso.Position local EndPos = Target.Torso.Position local path = PathService:FindPathAsync(StartPos, EndPos) local Waypoints = path:GetWaypoints() for _, waypoint in pairs(Waypoints) do Humanoid:MoveTo(waypoint.Position) LoadedAnimation:Play() Humanoid.MoveToFinished:Wait(2) end wait(0) end
Since its a loop, of course the animation would keep re playing without actually finishing. I was wondering if there was a way to make it so the animation just plays when moving and that's all.
Could you not just set the Animation Priority to Action (or Movement if it's a walking animation).
local Humanoid = script.Parent:WaitForChild("Humanoid") local Torso = script.Parent:WaitForChild("Torso") local Animation = Instance.new("Animation") Animation.AnimationId = "http://www.roblox.com/asset/?id=180426354" local LoadedAnimation = Humanoid:LoadAnimation(Animation) LoadedAnimation:Play() while true do local targetName = script.Parent:WaitForChild("Target") local PathService = game:GetService("PathfindingService") local Target = workspace:WaitForChild(targetName.Value) local StartPos = Torso.Position local EndPos = Target.Torso.Position local path = PathService:FindPathAsync(StartPos, EndPos) local Waypoints = path:GetWaypoints() for _, waypoint in pairs(Waypoints) do Humanoid:MoveTo(waypoint.Position) Humanoid.MoveToFinished:Wait(1) end wait() end
Since the NPC won't ever be without a target, running never has to stop. On touch of the NPC you just get teleported somewhere. Issue Solved...