So, I am making a crouching script but when you press the E key, it plays but it will not stop playing. I have the animation type set to action, and the animation is looped. I know that the reason why it's not working is because it's looping, but I want it to stop when the player takes their finger off the E key. I did not get any errors. Here's my code.
local userinputservice = game:GetService("UserInputService") local humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid") local animation = script:WaitForChild("Animation") local dance = humanoid:LoadAnimation(animation) userinputservice.InputBegan:Connect(function(input,process) local humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid") local animation = script.Animation local dance = humanoid:LoadAnimation(animation) if input.KeyCode == Enum.KeyCode.E then dance:Play() end end) userinputservice.InputEnded:Connect(function(input,process) if input.KeyCode == Enum.KeyCode.E then print('i') dance:Stop() end end)