anim.Stopped:Wait() not working

Hello everyone, I am currently stuck with an issue. I am trying to make an AI stop at a part and do a task. (In this case he is simply doing dishes). All the code i supposed to do is play an animation 5 times once it reaches the part. Howev


er, once the AI reaches the part, he does the animation over and over without stopping. The output only prints out “1” too. (See in the screenshot where I said print(i). Please help. If you need any additional info to help me solve, just let me know.

You can also do it this way:

function idletasks.WashDishes()
    neighbor:PivotTo(idletasks.Tasks.WashDishes.AnimPart.CFrame)
    local anim = humanoid.Animator:LoadAnimation(idletasks.Tasks.WashDishes.Animation)
    
    for i = 1, 5, 1 do
        task.wait() 
        print(i)
        anim:Play()
        task.wait(anim.Length)
        anim:Stop()
    end

    return idletasks
end

SO it pretty much works but for some reason the very first time the AI reaches that part and plays the animation, it does it once and only once. But every time next, it does it perfectly fine. Im not sure why, so here is a clip of the first time the AI walks to that part (take a look at the output):

Also, in case, here is a screenshot from the server script that actually calls the function from the module script:
Screenshot 2025-01-04 171437

Glad to help! I’m not entirely sure why that happens, also nice Hello Neighbor game.

Thanks! Glad I can finally get the neighbor washing some dishes :slight_smile: