when I run my animation it will run then rewind back and go back to normal. in making a crouch feature so I don't want it to rewind here is my code
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
function onKeyPress(inputObject, gameProcessed)
print("key pressed")
print(inputObject.KeyCode)
if inputObject.KeyCode == Enum.KeyCode.E then
print("E pressed")
local humanoid = player.Character:WaitForChild("Humanoid")
local ani = humanoid:LoadAnimation(game.animations.Animation)
ani:Play()
ani.Stopped:Connect(function()
print("stopped")
end)
end
end
UserInputService.InputBegan:Connect(onKeyPress)
this code technically works but it doesn't do exactly what I want to do. I want it to stay crouching but instead, it crouches then stands back up
UserInputService.InputBegan:Connect(onKeyPress)

1 comment
try by not loading the animation onto the humanoid inside of the function, put it outside so it only loads once. second off, humanoid:LoadAnimation has become deprecated, you should be using humanoid.Animator:LoadAnimation but keep in mind that the animator has to be created server side and then parented to the humanoid