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 9 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

Mouse = game.Players.LocalPlayer:GetMouse()

Prone = false
Player = game.Players.LocalPlayer.Character

Mouse.KeyUp:connect(function(Key)
    print("Key "..Key.." down.")
    if Key == "c" then
        print("Prone key down.")
        local Animation = Player.Humanoid:LoadAnimation(script.Lie)
        if Prone == false then
            print("Prone is false.")
            Prone = true
            Animation:Play()
            Player.Humanoid.CameraOffset = Vector3.new(0,-4,-1.5)
        else
            print("Prone is true.")
            Animation:Stop()
            --Animation = Player.Humanoid:LoadAnimation(script.Animation)
            --Animation:Play()
            Player.Humanoid.CameraOffset = Vector3.new(0,0,0)
            Prone = false
        end
    end
end)

1 answer

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

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

Mouse = game.Players.LocalPlayer:GetMouse()

Prone = false
Player = game.Players.LocalPlayer.Character

Animation = Player.Humanoid:LoadAnimation(script.Lie)

Mouse.KeyUp:connect(function(Key)
    print("Key "..Key.." down.")
    if Key == "c" then
        print("Prone key down.")
        if Prone == false then
            print("Prone is false.")
                 Prone = true
            Animation:Play()
            Player.Humanoid.CameraOffset = Vector3.new(0,-4,-1.5)
        else
            print("Prone is true.")
            Animation:Stop()
            --Animation = Player.Humanoid:LoadAnimation(script.Animation)
            --Animation:Play()
            Player.Humanoid.CameraOffset = Vector3.new(0,0,0)
            Prone = false
        end
    end
end)

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 — 9y
Ad

Answer this question