Hello! This is a tutorial about how to make a crawling animation like the one you see in Piggy or Teddy, and lets you go trough narrow gaps easily! (This will be kinda similar to GnomeCode’s tutorial, but I’ll add some extra stuff to the scripts!)
This Tutorial covers UserInputService, so the player can crawl when pressing the left Ctrl key.
So, let’s get into it!
1) Making an Animation
This part is about making an Animation. You can use Moon Animator if you want to, but the Original Animation Editor works aswell. And now you can make your Crawling animation that plays whenever you press Ctrl. It could be crawling, or crouching, it’s up to you. Once you’re done, set the Animation Priority to Movement By clicking the three dots next to the play button (or pressing 8 in Moon Animator), then Publishing it to Roblox (Or Clicking “Export all” In Moon Animator)
2) Making the script
Finally, the technical part! But first:
- Get Your animation ID, insert an Animation object into workspace, and paste the Animation ID into AnimationID
- Insert a LocalScript into StarterCharacterScripts, and put the Animation object inside the LocalScript.
And finally, Here’s the code:
local UserInputService = game:GetService("UserInputService")
local player = script.Parent -- in this case, the player will be the parent of the script.
local hum = player:WaitForChild("Humanoid")
local anim = hum:LoadAnimation(script:WaitForChild("Animation")) --If you renamed your animation, then consider changing the "Animation" to your animation name!
hum.Running:Connect(function(speed)
if speed > 0 then
anim:AdjustSpeed(1)
else
anim:AdjustSpeed(0)
end
end)
local crawling = false -- debounce
UserInputService.InputBegan:Connect(function(input, isTyping)
if not isTyping then -- if the player isn't typing in the chat
if input.KeyCode == Enum.KeyCode.LeftControl then
if not crawling then
crawling = true
anim:Play()
anim:AdjustSpeed(0)
hum.WalkSpeed = 8
hum.JumpPower = 0 -- NOTE: Head into StarterPlayer, and set "CharacterUseJumpPower" to true, since it's using "CharacterJumpHeight" currently.
hum.HipHeight = 0.3 -- yes, you have to set this to 0.3, or else you'll be floating in the air. (if you're making an R6 animation, then change this to -0.3)
else
anim:Stop()
hum.WalkSpeed = 16
hum.JumpPower = 50
hum.HipHeight = 2 -- (Set this to 0 in case your animation is R6)
crawling = false
end
end
end
end)
4) Test Time!
Let’s test what we’ve done. If you’ve done all of this correctly (or just copied the entire code), your work should function without errors. If you want to, you can build a vent in a wall to see if the player crawls through.
Hope that I helped!
Yes, this is my first tutorial, how did you guess?