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

How do I get this looped animation to stop?

Asked by 10 years ago

I have a looped animation named Lie with only 1 keyframe wich is at 0 seconds, the only animated part is the torso and the priority is Action.

I found this and I tried these things but it did not work: https://scriptinghelpers.org/questions/13447/properly-stop-animations

The Stop() function doesen't seem to work.

The animation starts, all prints work right and it gives no error.

I tried starting a new animation wich is blank and has core priority, but it did not work.

Animation ID: c3b2824fa4becf2c6ee2f20972de6604

01Mouse = game.Players.LocalPlayer:GetMouse()
02 
03Prone = false
04Player = game.Players.LocalPlayer.Character
05 
06Mouse.KeyUp:connect(function(Key)
07    print("Key "..Key.." down.")
08    if Key == "c" then
09        print("Prone key down.")
10        local Animation = Player.Humanoid:LoadAnimation(script.Lie)
11        if Prone == false then
12            print("Prone is false.")
13            Prone = true
14            Animation:Play()
15            Player.Humanoid.CameraOffset = Vector3.new(0,-4,-1.5)
View all 25 lines...

1 answer

Log in to vote
1
Answered by
Redbullusa 1580 Moderation Voter
10 years ago

I'd load the Animation outside of the anonymous function's scope.

01Mouse = game.Players.LocalPlayer:GetMouse()
02 
03Prone = false
04Player = game.Players.LocalPlayer.Character
05 
06Animation = Player.Humanoid:LoadAnimation(script.Lie)
07 
08Mouse.KeyUp:connect(function(Key)
09    print("Key "..Key.." down.")
10    if Key == "c" then
11        print("Prone key down.")
12        if Prone == false then
13            print("Prone is false.")
14                 Prone = true
15            Animation:Play()
View all 26 lines...

The LoadAnimation method creates a packet of information that is stored inside of the humanoid that will not go away.

It's not a good idea to put it locally inside of the function, because every time a key is up, you're loading more packets information.

Yes, it won't do anything because loading an animation will make the animation dormant. But since you're always playing it within the function, every animation you've loaded will be played, therefore making it impossible for the animations to stop.

That's why I made the Animation variable a static one, rather than a local one.

0
It worked! Thank you so much, I feel like I owe you now. I also had to add a bit that waited for the script to be in a Backpack. Hullburg 12 — 10y
Ad

Answer this question