input.InputBegan & Animation Help

  1. What do you want to achieve? Keep it simple and clear!
    So recently I’ve been working on part of a gun script and I want to get the gun to play two animations and speed up the player when LeftShift is held.
    (One animation is transition from aiming to holding it near the chest, another is just holding it near the chest).

  2. What is the issue? Include screenshots / videos if possible!
    When LeftShift is held down, the first animation keeps repeating, and I’m not even sure if the second one is even happening due to the first one repeating.
    (The WalkSpeed works however).

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I looked on the Developer Hub, but there isn’t much on animations and inputbegan. I already went back and checked the first animation to see if it is looped. Both animations are set on action.

Here comes part of the script down here!

userInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		shiftDown = true
	end
	
	
	if shiftDown then
		animation3 = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.HoldClosing)
		animation3:Play()
		if animation3.Stopped then
			animation4 = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.HoldClosingPerm)
			animation4:Play()
		end
	end
end)

userInputService.inputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		shiftDown = false
	end
end)

while wait() do
	if shiftDown then
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 25
	else
		shiftDown = false
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
	end
end

You should be looking for animation3 and animation4 for the animations themselves. This is in a local script.

3 Likes

Try changing the animations priority for the looped animation to something higher

Same exact scenario occurred. I don’t think the priorities are the problem.

Right, I’m a total idiot.

Apparently the second animation wasn’t looped like it was supposed to.

1 Like