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

How do I fix this crouching animation?

I'm trying to make a script that allows players to play a crouching animation, move slower, and jump lower when the R1 button is pressed, the player crouches and their mobility is reduced, but they won't return to the idle animation when the button is released, I'm sure the problem has to do with how the crouching script is below the idle script. (Note: The script is based off the "run with the R1 button" script.)

		-- Make character stand if R1 is released
		if input.KeyCode == Enum.KeyCode.ButtonR1 then
        
character.Humanoid.WalkSpeed = 22
character.Humanoid.JumpPower = 50


		end
	end
end)
 
-- Check for user input began events. This handles ducking.
userInputService.InputBegan:connect(function(input, processed)
	if input.UserInputType == Enum.UserInputType.Gamepad1 then
		
		-- If R1 is pressed then make the character duck.
		if input.KeyCode == Enum.KeyCode.ButtonR1 then
			
local duck = character.Humanoid:LoadAnimation(script.Parent.Crouch)         
duck:Play()
character.Humanoid.WalkSpeed = 6
character.Humanoid.JumpPower = 25
		end
	end
end)

1 answer

Update: I found the right spot to put the duck:Stop() function

		-- Make character stand if R1 is released
		if input.KeyCode == Enum.KeyCode.ButtonR1 then
			duck:Stop()     
character.Humanoid.WalkSpeed = 22
character.Humanoid.JumpPower = 50

		end
	end
end)
 
-- Check for user input began events. Handles ducking.
userInputService.InputBegan:connect(function(input, processed)
	if input.UserInputType == Enum.UserInputType.Gamepad1 then
		
		-- If R1 is pressed then make the character duck. 
		if input.KeyCode == Enum.KeyCode.ButtonR1 then
		duck:Play()
character.Humanoid.WalkSpeed = 6
character.Humanoid.JumpPower = 25

		end
	end
end)

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