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