Animation doesn't stop when i want to

Hi! I’m creating a fighting game and when I try to stop an animation, it doesn’t stop. It’s only on forward animation because I have a backward animation and it works fine.

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if  input.KeyCode == duck then
		if not duckAnimTrack.IsPlaying then
			duckAnimTrack:Play()
			idleAnimTrack:Stop()
			forwardAnimTrack:Stop()
			hum.WalkSpeed= 0
		end
	end
	
	
	if input.KeyCode == backward then
		if not backwardAnimTrack.IsPlaying then
			backwardAnimTrack:Play()
		end
	end
		
		
	if input.KeyCode == forward then
		if not forwardAnimTrack.IsPlaying then
			forwardAnimTrack:Play()
		end
	end
end)



UserInputService.InputEnded:Connect(function(input, gameProcessedEvent)
		if input.KeyCode == backward then
		if backwardAnimTrack.IsPlaying then
			backwardAnimTrack:Stop()
		end
	end 
	
	if input.KeyCode == forward then
		if forwardAnimTrack.IsPlaying then
			forwardAnimTrack:Stop()
		end
	end 
	
	if  input.KeyCode == duck then
		if duckAnimTrack.IsPlaying then
			idleAnimTrack:Play()
			hum.WalkSpeed= 16
			duckAnimTrack:Stop()
			forwardAnimTrack:Stop()
		end
	end

end)

Help please!

Is the Animation on looped? if so turn it off (You will have to redo the animation)

how can i see if the animation is on looped?

nevermind, i found it… and it doesn’t work (it was already turn off)

image

Can we see your variables?

local Player = game:GetService("Players").LocalPlayer

local char = Player.Character or Player.CharacterAdded:Wait()

local hum = char:WaitForChild("Humanoid")

local UserInputService = game:GetService("UserInputService")

hum.JumpPower = 10

local idleAnim = script.Idle --IDLE

local forwardAnim = script.a --FORWARD

local backwardAnim = script.b --BACKWARD

local duckAnim = script.Duck

local forwardAnimTrack = hum.Animator:LoadAnimation(forwardAnim)

local backwardAnimTrack = hum.Animator:LoadAnimation(backwardAnim)

local idleAnimTrack = hum.Animator:LoadAnimation(idleAnim)

local duckAnimTrack = hum.Animator:LoadAnimation(duckAnim)

local forward = Enum.KeyCode.D

local backward = Enum.KeyCode.A

local jump = Enum.KeyCode.W

local duck = Enum.KeyCode.S

local canjump = true

local canmove = true

idleAnimTrack:Play()

if duckAnimTrack.IsPlaying and backwardAnimTrack.IsPlaying and forwardAnimTrack.IsPlaying then

idleAnimTrack:Stop()

end

if duckAnimTrack.IsPlaying then

forwardAnimTrack:Stop()

end

Ah! Cant wait to see this game in action!

Cant you just call

looped = false

on the animation?

Sorry, it doesn’t work :frowning:

btw this is my first ever project on roblox studio so I’m a begginner on this, thanks for the words

Ah, then probably turn off Looped.

you can use IsPlaying to check if the animation is playing and if it is stop it.
Here’s an example:

if anim.IsPlaying then
			anim:Stop()
		end

I just did that and the animation is still playing
image

Then your best bet is to check the animation itself preferably the priorities

It’s on movement, and if i change it to core it doesn’t play anymore

you can label (name) keyframes in your animation. the reason you should do this is it code can detect when named keyframes have been reached so if you have a keyframe you want the animation to end on and everything to go back to normal you can detect the end keyframe and stop the animation and revert all the changes u made to run the animation such as walkspeed