Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Crouching script will not work properly. Could somebody help?

Asked by 4 years ago
Edited 4 years ago

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)
0
you must not re-load the animation on InputBegan, the animation track you're calling :Stop() on is different from the one you're playing. Luathron 185 — 4y
0
oh jorcorrs 76 — 4y

Answer this question