I want to make an R6 crouch script, but I don’t know how to do it.
The problem is that I want the animation to pause when the player stops moving. I have tried to detect the plays move direction, and make the adjust speed 0.001, but it only worked when I just pressed C, not when I stopped moving. The animation would only play if the player was walking when they pressed C, not when they press C, then walk. Here is the code:
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local char = player.Character
UIS.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.C then
char.Humanoid.WalkSpeed = 8
local Anim = Instance.new("Animation")
Anim.AnimationId = "rbxassetid://6616895835"
PlayAnim = char.Humanoid:LoadAnimation(Anim)
PlayAnim:Play()
end
end)
UIS.InputEnded:connect(function(input)
if input.KeyCode == Enum.KeyCode.C then
char.Humanoid.WalkSpeed = 16
PlayAnim:Stop()
end
end)
I have tried to find tutorials and I also looked on the devforum a lot, but I have found nothing.
Also, I am using User Input Service instead of Context Action Service, because I don’t know how to use Context Action Service, and also because the game isn’t easily playable on mobile.
Please let me know any solutions, and if I have to use context action service, I’ll try to learn it.
You could create two animations, an idle crouch and movement crouch. Then when you crouch play the idle crouch and only play the moving crouch if you’re moving while crouched.
I’ll try that, but the biggest problem is when the player presses C then walks, it plays the normal walking animation. I might have a fix for that, but I’ll make an idle crouching animation. Thank you!
Make sure that the crouch idle and crouch walk animations have a higher priority than that core animations. This will avoid walk animation from overriding your crouch.
Hello, I did a script for my game a time ago. Here is my Script [ Put a it in a LocalScript inside of StarterPlayer > StarterCharacterScripts ]:
--//UserInputService\\--
local UIS = game:GetService('UserInputService')
--//Character and Descendants\\--
local Character = script.Parent
local Humanoid = Character:WaitForChild('Humanoid')
--//Animations\\--
local Animations = Instance.new('Configuration', Character)
Animations.Name = 'Animations'
local CrouchAnimation = Instance.new('Animation', Animations)
CrouchAnimation.AnimationId = 'rbxassetid://6587009470'
CrouchAnimation.Name = 'CrouchAnimation'
--//Load Animations\\--
local LoadCrouchAnimation = Humanoid:LoadAnimation(CrouchAnimation)
LoadCrouchAnimation.Looped = true
--//Scripting\\--
UIS.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.LeftControl or Input.KeyCode == Enum.KeyCode.RightControl then
if Humanoid.Health > 0 then
Humanoid.WalkSpeed = 5
Character.HumanoidRootPart.Running.PlaybackSpeed = 0.70
LoadCrouchAnimation:Play()
while wait() do
if Humanoid.MoveDirection.Magnitude > 0 then
LoadCrouchAnimation:AdjustSpeed(0.5) --<<<You can use LoadCrouchAnimation:AdjustSpeed(1) too.
else
LoadCrouchAnimation:AdjustSpeed(0)
end
end
end
end
end)
UIS.InputEnded:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.LeftControl or Input.KeyCode == Enum.KeyCode.RightControl then
LoadCrouchAnimation:Stop()
Character.HumanoidRootPart.Running.PlaybackSpeed = 1
Humanoid.WalkSpeed = 16
end
end)