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

How do I get this looped animation to stop?

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

✓ Accepted answer

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.

1 comment

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.

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