Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you make the animation play uninterrupted?

Asked by 3 years ago
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.

2 answers

Log in to vote
0
Answered by
pwx 1581 Moderation Voter
3 years ago
Edited 3 years ago

Could you not just set the Animation Priority to Action (or Movement if it's a walking animation).

0
How would I include that into the script though??? tightanfall 110 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
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...

Answer this question