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

How could I stop an animation from another script?

Asked by 7 years ago

I understand the use of the _G variable but it doesn't work because this animation is in a function. Are there any way I can solve it? Here is some code.

_G.KillAnim = plrs.Character:WaitForChild("Humanoid"):LoadAnimation(script.KillDragging) 
_G.SurvAnim = char:WaitForChild("Humanoid"):LoadAnimation(script.Dragging2)

 _G.KillAnim:Play()
_G.SurvAnim:Play()

The thing with that is, it wouldn't let me get the variable from a different script because it was inside of a scope, any ideas on how I could solve it?

2 answers

Log in to vote
0
Answered by 7 years ago

You can use GetPlayingAnimationTracks on the Humanoid to stop the animation.

for i,v in pairs(humanoid:GetPlayingAnimationTracks()) do
    if v.Name == "Animation name here" then
        v:Stop()
    end
end
Ad
Log in to vote
0
Answered by 7 years ago

Don't use global variables. It's really not a good idea when it comes to animations, unless you know 100% what you're doing. Use a RemoteEvent. You can find tons of tutorials for this on YouTube.

Upvote if this helped! :)

0
Well wouldn't I have to go into another scope just to retrieve that data? Well I guess I could send the needed stuff to every script that would have to stop the animation right? But how would I stop said animation from a different script without accessing the variable I used to play the animation? xXLegendarySoldierXx 129 — 7y

Answer this question