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

How do I stop this animation in an NPC?

Asked by
s9i 2
4 years ago

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

Log in to vote
0
Answered by
xdeno 187
4 years ago

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()
0
Thank you! s9i 2 — 4y
Ad

Answer this question