#Having trouble with crawling animation

1 messages · Page 1 of 1 (latest)

foggy patrol
#

Basically, I'm trying to make it so that when the player holds LShift, they go into a crawling animation, and when they release LShift, they stand back up. While I've managed to make it work, for some reason, EVERY input causes "Player has stopped crawling" to print. How can I fix this?

warm kayakBOT
#

studio** You are now Level 1! **studio

short monolith
#

Can you give me the full code?

foggy patrol
#
local crawlIdle = script:WaitForChild("CrawlIdle")
local player = script.Parent
local humanoid = player:WaitForChild("Humanoid")
local idleTrack = humanoid:LoadAnimation(crawlIdle)
local UIS = game:GetService("UserInputService")


UIS.InputBegan:Connect(function(input,gameProcessedEvent)
    if (UIS:IsKeyDown(Enum.KeyCode.LeftShift)) == true then
        idleTrack:Play()
        print("Player is crawling")
    end
end)

UIS.InputEnded:Connect(function(input,gameProcessedEvent)
    if (UIS:IsKeyDown(Enum.KeyCode.LeftShift)) == not true then
        idleTrack:Stop()
        print("Player has stopped crawling")
    end
end)```
#

you mean like that?

gentle blade
foggy patrol
#

💀

short monolith
#

🤣

#

nah🤣

gentle blade
gentle blade
foggy patrol
#

Oh my god thank you

rough thicket
gentle blade
gentle blade
foggy patrol
#

I'm not sure what to do to get around that 😭
I'm really new to coding but I guess I'll play around and see if I can find something that works

peak pelican
#

add this:

#
if input.KeyCode == Enum.KeyCode.LeftShift then
--- your other code inside here
end
#

into your input detection events

#

or, just the last one really

foggy patrol
#

replacing (UIS:IsKeyDown(Enum.KeyCode.LeftShift)) == false with input.KeyCode == Enum.KeyCode.LeftShift has the same result

peak pelican
#

oh wait

#

well, your code should just work even without that

#

tbh you dont even need it

foggy patrol
#

I mean it DOES

peak pelican
#

that's a fine place to add it tho, i suppose

foggy patrol
#

but I don't want "Player has stopped crawling" to constantly print

warm kayakBOT
#

studio** You are now Level 2! **studio

foggy patrol
#

I feel like that's gonna cause a problem or something later down the line

#

Does printing cause lag at all?

peak pelican
#

hmm. should be fine for the most part

peak pelican
#

unless you open the dev console lol but no its fine

foggy patrol
#

Ah

#

I guess I'll just keep the current code then

#

wait

foggy patrol
#

when did I even-

pseudo dune
#

not true 😭

foggy patrol
#

Oh wait nvm I might be able to fix it

#

Unsure
I made a crawling animation for when the player moves, but it doesn't stop when I let go of WASD

#
local crawlMove = script:WaitForChild("CrawlMove")
local player = script.Parent
local humanoid = player:WaitForChild("Humanoid")
local idleTrack = humanoid:LoadAnimation(crawlIdle)
local moveTrack = humanoid:LoadAnimation(crawlMove)
local UIS = game:GetService("UserInputService")
local moveCheck = false

UIS.InputBegan:Connect(function(input,gameProcessedEvent)

    local keyW = input.KeyCode == Enum.KeyCode.W
    local keyA = input.KeyCode == Enum.KeyCode.A
    local keyS = input.KeyCode == Enum.KeyCode.S
    local keyD = input.KeyCode == Enum.KeyCode.D

    if (UIS:IsKeyDown(Enum.KeyCode.LeftShift)) == true then
        idleTrack:Play(0.2)
        
        if humanoid then
            humanoid.WalkSpeed = 8
        end
    end
    if keyW and (UIS:IsKeyDown(Enum.KeyCode.LeftShift)) == true then
        moveCheck = true
    end
    if keyA and (UIS:IsKeyDown(Enum.KeyCode.LeftShift)) == true then
        moveCheck = true
    end
    if keyS and (UIS:IsKeyDown(Enum.KeyCode.LeftShift)) == true then
        moveCheck = true
    end
    if keyD and (UIS:IsKeyDown(Enum.KeyCode.LeftShift)) == true then
        moveCheck = true
    end
    
    if moveCheck == true then
        moveTrack:Play()
    end
end)

UIS.InputEnded:Connect(function(input,gameProcessedEvent)
    
    local keyW = input.KeyCode == Enum.KeyCode.W
    local keyA = input.KeyCode == Enum.KeyCode.A
    local keyS = input.KeyCode == Enum.KeyCode.S
    local keyD = input.KeyCode == Enum.KeyCode.D
    
    if UIS:IsKeyDown(Enum.KeyCode.LeftShift) == false then
        idleTrack:Stop(0.2)
        moveCheck = false
        
        if humanoid then
            humanoid.WalkSpeed = 13
        end
    end
    
    if keyW and keyA and keyS and keyD == false then
        moveCheck = false
    end
    
    if moveCheck == false then
        moveTrack:Stop()
    end
end)```
#

hmm
apparently moveCheck only goes false when I let go of LShift, interesting

#

the animation also restarts every time I make another input 😭

#

Imma try something

#

Oh wait I'm actually so stupid