Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How could I stop an animation from another script?

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

✓ Accepted answer

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

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! :)

1 comment

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?

This discussion is preserved as it was. New answers, comments, and votes are closed.