How to pause and unpause animation based on Character Movement?
I want a script that uses crouching animation, and when pressing a key it enables (but animation speed is 0) when character is moving animation speed is 1, and when character stops moving animation speed is 0 again. If they press the hotkey again, they are back to walking.
I have a script but there’s a problem where it only detects when I press the hotkey, not while I am walking.
Video showing problem & what I want:
https://drive.google.com/file/d/1q_DGXxo3Hxlfujl1KzhPNL-SYIrgYnJU/view
The script I have currently:
02 | local PlayerSerivce = game:GetService( "Players" ) |
03 | local Player = PlayerSerivce.LocalPlayer |
04 | local Character = Player.Character |
05 | local Humanoid = Character:WaitForChild( "Humanoid" ) |
06 | local AnimationID = game:GetService( "ReplicatedStorage" ).Crawl.AnimationId |
07 | local CharacterAnimation |
08 | game:GetService( "UserInputService" ).InputBegan:Connect( function (inputObject, gameProcessedEvent) |
09 | if inputObject.KeyCode = = Enum.KeyCode [ Hotkey ] then |
15 | local CrawlAnimation = Character:FindFirstChild( "AnimationCharacter" ) |
16 | if CharacterAnimation then |
17 | CharacterAnimation:Stop() |
19 | if CrawlAnimation then |
20 | if CrawlAnimation.AnimationId = = AnimationID then |
21 | CrawlAnimation:Destroy() |
24 | CrawlAnimation:Destroy() |
26 | local Animation = Instance.new( "Animation" ,Character) |
27 | Animation.Name = "AnimationCharacter" |
28 | Animation.AnimationId = AnimationID |
29 | CharacterAnimation = Character.Humanoid:LoadAnimation(Animation) |
30 | if Humanoid.MoveDirection.Magnitude > 0 then |
31 | CharacterAnimation:Play() |
32 | CharacterAnimation:AdjustSpeed( 1 ) |
34 | if Humanoid.MoveDirection.Magnitude < = 0 then |
35 | CharacterAnimation:Play() |
36 | CharacterAnimation:AdjustSpeed( 0 ) |