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

How to pause and unpause animation based on Character Movement?

Asked by 2 years ago

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:

01local Hotkey = "C"
02local PlayerSerivce = game:GetService("Players")
03local Player = PlayerSerivce.LocalPlayer
04local Character = Player.Character
05local Humanoid = Character:WaitForChild("Humanoid")
06local AnimationID = game:GetService("ReplicatedStorage").Crawl.AnimationId
07local CharacterAnimation
08game:GetService("UserInputService").InputBegan:Connect(function(inputObject, gameProcessedEvent)
09    if inputObject.KeyCode == Enum.KeyCode[Hotkey] then
10        animation()
11    end
12end)
13function animation()
14    if Character then
15        local CrawlAnimation = Character:FindFirstChild("AnimationCharacter")
View all 39 lines...

1 answer

Log in to vote
1
Answered by
Puppynniko 1059 Moderation Voter
2 years ago
Edited 2 years ago

i fixed the script for you, you need to detect if the player is moving using Humanoid.Running or walking so you can stop the animation when plr is not moving

01local Hotkey = "C"
02local PlayerSerivce = game:GetService("Players")
03local Player = PlayerSerivce.LocalPlayer
04local Character = Player.Character
05local Humanoid = Character:WaitForChild("Humanoid")
06local CharacterAnimation
07local IsCrawl = false
08CharacterAnimation = Character.Humanoid:LoadAnimation(script:WaitForChild("Crawl"))
09local function Animate()
10    Humanoid.WalkSpeed = 5
11    if not IsCrawl then
12        CharacterAnimation:Play()
13        CharacterAnimation:AdjustSpeed(0)
14        Humanoid:SetStateEnabled(Enum.HumanoidStateType.Climbing, false)
15        Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
View all 37 lines...
Ad

Answer this question