Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How To Make an Improved Crouch/Crawl Animation?

Hello, I was recently watching one of AlvinBlox's tutorials (How to Make a Piggy Game) and I got to the part where he showed us how to make a crouching animation. Everything worked exactly how he scripted it, but I was wondering how I could improve it. There is a place for only one animation ID, the idle crouch animation, but no crawling animation. I was wondering if there was a way to add a crawling animation onto the script. Here's the script:

-- Piggy "Anims" Script
-- Description: Handles animations for crouching and turning the crouch GUI on/off at different times.
-- Creator: AlvinBlox (Alvin_Blox)

-- Created: 22/04/2020 20:16 GMT

-- This code has been distributed to Premium Channel Members of the AlvinBlox YouTube Channel ONLY (https://www.youtube.com/alvinblox)
-- Do not redistribute. 

local player = game.Players.LocalPlayer

local userInputService = game:GetService("UserInputService")

local animationID = "rbxassetid://181091341"

local animPlaying = false

function crouch()
	if player:FindFirstChild("Contestant") then
		if animPlaying == false then
			local animObj = Instance.new("Animation")
			animObj.AnimationId = animationID
			local loadedAnim = player.Character.Humanoid:LoadAnimation(animObj)
			loadedAnim:Play()
			player.Character.Humanoid.WalkSpeed = 10
			animPlaying = true
			script.Parent.Crouch.ImageColor3 = Color3.fromRGB(26, 144, 255)
			script.Parent.Crouch.TextLabel.BackgroundColor3 = Color3.fromRGB(26, 144, 255)
			print("Playing")
		else
			print("Stopping")
			for i , v in pairs(player.Character.Humanoid:GetPlayingAnimationTracks()) do
				v:Stop()
			end
			player.Character.Humanoid.WalkSpeed = 16
			animPlaying = false
			script.Parent.Crouch.ImageColor3 = Color3.fromRGB(255,255,255)
			script.Parent.Crouch.TextLabel.BackgroundColor3 = Color3.fromRGB(255,255,255)
		end
	end
end

userInputService.InputBegan:Connect(function(input,gpe)
	if input.KeyCode == Enum.KeyCode.LeftControl then
		print("Correct input")
		crouch()
	end
end)

script.Parent.Crouch.MouseButton1Click:Connect(function()
	crouch()
end)

game.ReplicatedStorage.ToggleCrouch.OnClientEvent:Connect(function(visiblity)
	script.Parent.Crouch.Visible = visiblity
	for i , v in pairs(player.Character.Humanoid:GetPlayingAnimationTracks()) do
		v:Stop()
	end
	player.Character.Humanoid.WalkSpeed = 16
	animPlaying = false
	script.Parent.Crouch.ImageColor3 = Color3.fromRGB(255,255,255)
	script.Parent.Crouch.TextLabel.BackgroundColor3 = Color3.fromRGB(255,255,255)
end)

Here are some GIFS to show you what it looks like: What I want: https://giphy.com/gifs/dagWSKzg6Um6WMhyp5 What the script does: https://giphy.com/gifs/XGyX3ZMyckqWsr1V2c

Thanks in advance!

                                         ~Trashy

1 comment

0

Hey! what you need to do is you need to click the 3 dots then click set animation priority, then you set it to action. Hope I helped!

2 answers

If you get the plugins Build Rig and Animation Editor you can use those. It is pretty easy to learn how to use them.

2 comments

0

Yes, I used the Animation Editor to create an animation, but I was wondering how I can actually insert the walking animation into the script along with the idle animation, since there is only a place to put one animation ID, thanks!

0

Hey! what you need to do is you need to click the 3 dots then click set animation priority, then you set it to action. Hope I helped!

Hey! what you need to do is you need to click the 3 dots then click set animation priority, then you set it to action. Hope I helped!

This discussion is preserved as it was. New answers, comments, and votes are closed.