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

Animation doesn't play but everything else works?

Asked by 3 years ago

I'm trying to make npcs walk to parts, which works, but when I try to play the animation it doesn't work, does anyone have a fix?

while wait(0.25) do
script.Parent:MoveTo(game.Workspace.Path.Part3.Position)
    script.Parent.MoveToFinished:Wait()
    script.Parent:MoveTo(game.Workspace.Path.Part1.Position)
    script.Parent.MoveToFinished:Wait()
    script.Parent:MoveTo(game.Workspace.Path.Part4.Position)
    script.Parent.MoveToFinished:Wait()
    script.Parent:MoveTo(game.Workspace.Path.Part2.Position)
end

    local anim = script.Parent:LoadAnimation(script.Parent.Animation)
    anim:Play()

1 answer

Log in to vote
1
Answered by
Roger111 347 Moderation Voter
3 years ago
Edited 3 years ago

ANSWER: You put your while loop first so any code outside of the while loop will not run until the while loop has finished. (And your while loop never ends, therefore you never get to line 11 and 12.

FIX:

local anim = script.Parent:LoadAnimation(script.Parent.Animation)
anim:Play()

while wait(0.25) do
script.Parent:MoveTo(game.Workspace.Path.Part3.Position)
    script.Parent.MoveToFinished:Wait()
    script.Parent:MoveTo(game.Workspace.Path.Part1.Position)
    script.Parent.MoveToFinished:Wait()
    script.Parent:MoveTo(game.Workspace.Path.Part4.Position)
    script.Parent.MoveToFinished:Wait()
    script.Parent:MoveTo(game.Workspace.Path.Part2.Position)
end
Ad

Answer this question