Animation is not stopping

local Plr = game.Players.LocalPlayer
local UserinputService = game:GetService("UserInputService")

local MenacingParticle = game.ReplicatedStorage.Menacing
local AnimationStand = game.ReplicatedStorage.Animations.Stands.Animation
local IdleStand = game.ReplicatedStorage.Animations.Stands.Animation2

UserinputService.InputBegan:Connect(function(key,txt)
	if txt then return end
	if key.KeyCode == Enum.KeyCode.M then
		local AnimationTrack = Plr.Character.Humanoid:LoadAnimation(AnimationStand)
		local AnimationTrack2 = Plr.Character.Humanoid:LoadAnimation(IdleStand)
		AnimationTrack.Priority = Enum.AnimationPriority.Action
		AnimationTrack2.Priority = Enum.AnimationPriority.Core
		AnimationTrack2.Looped = true
		

		
		AnimationTrack:Play()
		
		wait(AnimationTrack.Length)
		
		AnimationTrack2:Play()
		
		MenacingParticle.Parent = Plr.Character.HumanoidRootPart
		
		
		
		
		
		
	end
end)

UserinputService.InputEnded:Connect(function(key,txt)
	if txt then return end
	if key.KeyCode == Enum.KeyCode.M then
		local AnimationTrack2 = Plr.Character.Humanoid:LoadAnimation(IdleStand)
		AnimationTrack2:Stop()
		
		
		
		
		
		
	end
end)

why wont my animation stop, still plays when i let go M.

2 Likes

Is the animation looped by any chance?

1 Like

Try loading your animations at the start of the script, instead of creating a new variable each time M goes up or down. Then simply play them and stop them in each function.

8 Likes

It looks like when you press m, it plays, waits, then plays it again. If you let go of m before it plays again it might play even if you aren’t pressing m

2 Likes

Untested code obviously, but it looks like your problem was you were loading another animation and stopping that one, instead of stopping the first one. Try this:

local Plr = game.Players.LocalPlayer
local UserinputService = game:GetService("UserInputService")

local MenacingParticle = game.ReplicatedStorage.Menacing
local AnimationTrack = Plr.Character.Humanoid:LoadAnimation(game.ReplicatedStorage.Animations.Stands.Animation)
local AnimationTrack2 = Plr.Character.Humanoid:LoadAnimation(game.ReplicatedStorage.Animations.Stands.Animation2)
AnimationTrack.Priority = Enum.AnimationPriority.Action
AnimationTrack2.Priority = Enum.AnimationPriority.Core
AnimationTrack2.Looped = true

UserinputService.InputBegan:Connect(function(key,txt)
	if txt then return end
	if key.KeyCode == Enum.KeyCode.M then
		AnimationTrack:Play()
		AnimationTrack.Stopped:wait()
		AnimationTrack2:Play()
		MenacingParticle.Parent = Plr.Character.HumanoidRootPart
	end
end)

UserinputService.InputEnded:Connect(function(key,txt)
	if txt then return end
	if key.KeyCode == Enum.KeyCode.M then
		AnimationTrack:Stop()
		wait()
		AnimationTrack2:Stop()
	end
end)

This code loads both of the animations at the start of the script, and starts/stops them as needed. You’ll also need to look at creating a remote event if you want other people to see that particle effect.

Thanks, that helped, ok, anyways thanks, repeating since you need 30 or more characters to reply lol,