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
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!