Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I stop this animation in an NPC?

The script I have plays an animation in an NPC named Martin. After 3 seconds, I want the animation to stop, but the animation still continues to loop after 3 seconds. Here is the script --

local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://4594895034"

local controller = game.Workspace.Martin.Zombie -- path to Humanoid/AnimationController
controller:LoadAnimation(anim):Play()
wait(3)
anim:Stop()

The "anim:Stop()" part just doesn't work. The script is located in Workspace, and holds the animations that I want to use for the NPC.

1 answer

✓ Accepted answer

You have to set a variable reference to the animation that has loaded which controls playing and stopping the animation, not the animation instance.

local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://4594895034"

local controller = game.Workspace.Martin.Zombie -- path to Humanoid/AnimationController
local Animation = controller:LoadAnimation(anim)
Animation:Play()
wait(3)
Animation:Stop()

1 comment

0

Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.