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

How do I stop my animation from looping?

Asked by
sngnn 274 Moderation Voter
4 years ago
Edited 4 years ago

I'm making a game, and whenever the player gets close to an NPC I'm making, the NPC will stop its animation and start a new one that makes it look at the player. However, the NPC pauses for a second when switching animations. My main problem, though, is that the animation loops. How can I fix this?

(By the way, it's not finished yet. All I have is the NPC playing an animation and after 5 seconds it plays the different animation.)

local animation = Instance.new("Animation")
animation.Parent = workspace.Dummy
animation.AnimationId = "rbxassetid://4718550145"

local humanoid = workspace.Dummy.Humanoid

local track = humanoid:LoadAnimation(animation)
track:Play()
wait(5)
track:Stop()
local look = Instance.new("Animation")
look.Parent = workspace.Dummy
look.AnimationId = "rbxassetid://4719138648"

local track2 = humanoid:LoadAnimation(look)
track2.Looped = false
track2:Play()

Edit: What I did wrong was set the animation priority to "Core" and not "Action". But I've encountered a new problem! I want the NPC to stay still at the last frame, but after the animation finished, the NPC just stands there.

0
Which animation is looping? The second one shouldn't since that you coded it not to. Norbunny 555 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

You can fix this by adding "track.Looped = false" if it's track one that is looping, which I'm assuming it is, because it's the one without Looped set to false.

I also just realised that you never put a "Stop()" under the second track, so I'll add that.

Use this:

local animation = Instance.new("Animation")
animation.Parent = workspace.Dummy
animation.AnimationId = "rbxassetid://4718550145"

local humanoid = workspace.Dummy.Humanoid

local track = humanoid:LoadAnimation(animation)
track.Looped = false
track:Play()
wait(5)
track:Stop()
local look = Instance.new("Animation")
look.Parent = workspace.Dummy
look.AnimationId = "rbxassetid://4719138648"

local track2 = humanoid:LoadAnimation(look)
track2.Looped = false
track2:Play()
wait(--time you want to be waited)
track2:Stop()
Ad

Answer this question