✓ Accepted answer
We ended up solving it on discord. Took a while but we got it done. Here is the final result:
If you are reading this and have any question, post them below pls and I'll get back to u.
local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local Character = Player.Character
local isCrouching = false
isOnCooldown = false
idleCrouchAnimation = nil
sneakAnimation = nil
function isRunning()
if
UIS:IsKeyDown(Enum.KeyCode.LeftShift) and UIS:IsKeyDown(Enum.KeyCode.LeftShift)
or UIS:IsKeyDown(Enum.KeyCode.W) and UIS:IsKeyDown(Enum.KeyCode.LeftShift)
or UIS:IsKeyDown(Enum.KeyCode.A) and UIS:IsKeyDown(Enum.KeyCode.LeftShift)
or UIS:IsKeyDown(Enum.KeyCode.S) and UIS:IsKeyDown(Enum.KeyCode.LeftShift)
or UIS:IsKeyDown(Enum.KeyCode.D) and UIS:IsKeyDown(Enum.KeyCode.LeftShift)
then
return true
end
end
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.C and not isOnCooldown then
isOnCooldown = true
if isRunning() then
else
if not isCrouching then
isCrouching = true
Character.Humanoid.WalkSpeed = 6
local animation = Instance.new('Animation')
animation.AnimationId = 'rbxassetid://04690414995'
idleCrouchAnimation = Character.Humanoid:LoadAnimation(animation)
idleCrouchAnimation:Play()
else
isCrouching = false
idleCrouchAnimation:Stop()
Character.Humanoid.WalkSpeed = 16
end
end
wait(.5)
isOnCooldown = false
elseif input.KeyCode == Enum.KeyCode.W and isCrouching then
local animation = Instance.new('Animation')
animation.AnimationId = 'rbxassetid://04690454085'
sneakAnimation = Character.Humanoid:LoadAnimation(animation)
sneakAnimation:Play()
end
end)
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
print(isRunning(), sneakAnimation)
if isRunning() and sneakAnimation then
sneakAnimation:Stop()
sneakAnimation = nil
end
if (input.KeyCode == Enum.KeyCode.LeftShift and UIS:IsKeyDown(Enum.KeyCode.W))
or (input.KeyCode == Enum.KeyCode.W and UIS:IsKeyDown(Enum.KeyCode.LeftShift)) then
idleCrouchAnimation:Stop()
end
end)
UIS.InputEnded:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.W and sneakAnimation then
sneakAnimation:Stop()
sneakAnimation = nil
end
end)
1 comment
make a local variable called Crouching and set it to false (local Crouching = false) and then when the player crouches you check if Crouching is true, if not then set it to true and crouch, otherwise set it to false and uncrouch.