Crouching script isn't working

I want to make a crouching script with a startup animation but for some reason it doesn’t really work.
It’s supposed to play an looping animation after the startup animation ends but it doesn’t play it properly. Plus the walking animation doesn’t work either.

I thought it might be because the animation wasn’t looped or the priority was low but even though I changed it, it didn’t work.

local plr = game.Players.LocalPlayer
local char = plr.Character

local hum = char:FindFirstChild("Humanoid")
local uis = game:GetService("UserInputService")

local Animator = hum:WaitForChild("Animator")
local CrouchAnim = game.ReplicatedStorage.Animations.CrouchStartup
local CrouchIdleAnim = game.ReplicatedStorage.Animations.CrouchIdle
local CrouchMoveAnim = game.ReplicatedStorage.Animations.CrouchWalk
local GetDownAnimation = Animator:LoadAnimation(CrouchAnim)
local LoopMoveAnimation = Animator:LoadAnimation(CrouchMoveAnim)
local LoopIdleAnimation = Animator:LoadAnimation(CrouchIdleAnim)
LoopIdleAnimation.Looped = true
LoopIdleAnimation.Priority = Enum.AnimationPriority.Action


uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.C then
		GetDownAnimation:Play()
		if GetDownAnimation.Stopped then
			LoopIdleAnimation:Play()
			local animateScript = char:WaitForChild("Animate")
			animateScript.run.RunAnim.AnimationId = "rbxassetid://11746311681" 
			animateScript.walk.WalkAnim.AnimationId = "rbxassetid://11746311681" 
			
		end
		
	end
end)

uis.InputEnded:Connect(function(input)
	LoopIdleAnimation:Stop()
	local animateScript = char:WaitForChild("Animate")
	animateScript.run.RunAnim.AnimationId = "rbxassetid://9635717140" 
	animateScript.walk.WalkAnim.AnimationId = "rbxassetid://9635717140"   
end)

robloxapp-20221204-2332533.wmv (2.1 MB)

It looks like there might be an issue with the animation IDs you’re using. The AnimationId property is used to specify which specific animation should be played when that particular action occurs. Make sure you are passing in valid Roblox asset IDs for each of the animations.

1 Like

Im pretty sure that this is not the issue, but I’ll double check just in case.

.Stopped is an event.

Try replacing:

With:

GetDownAnimation.Stopped:Connect(function()

1 Like

robloxapp-20221205-1512553.wmv (1.4 MB)

well, now I don’t even know whats happening

Your code here

Is now running, and it wasn’t before. The problem you have right now seems to be related to other scripts and it’s up to you to fix it.

Do you know any other way I could change the walking animation when the player is crouched? I thought of the walking animation changing when the player’s walk speed is less that 8, or something like that.

You could play the crouch-walk animation on loop and adjust the speed to 0 when the player stops walking, 1 when it’s moving.

1 Like

could you make an example script?

Humanoid.Running:Connect(function(speed)
	if speed > 0 then
		CrouchWalk:AdjustSpeed(1)
	else
		CrouchWalk:AdjustSpeed(0)
	end
end)
1 Like

Wouldn’t this just just change the speed of the animation?

Try making a place in roblox studio and use my script to test if it works with the suggestions you made. I gotta go right now.

Basically, imagine you have an animation for walk-crouch. If the speed 1, the animation will play (when the player is moving), if the speed is 0 the animation will freeze and it will be like an idle.

1 Like

so then its like

if humanoid.WalkSpeed = 1 then
animateScript.run.RunAnim,AnimationId =  "crouch walking id"

this would work?