-
What do you want to achieve? I want the animation to play only when the player is
holding CTRL and Moving -
What is the issue? Whenever ur standing still and u hold ctrl the crouch walk animation plays
local NormalWalkSpeed = 16
local CrouchSpeed = 10
local AnimID = "rbxassetid://13281476191"
local cas = game:GetService("ContextActionService")
local Leftc = Enum.KeyCode.LeftControl
local RightC = Enum.KeyCode.RightControl
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local Humanoid = char:WaitForChild("Humanoid")
local CrouchAnim = Instance.new("Animation")
CrouchAnim.AnimationId = AnimID
local CAnim = Humanoid:LoadAnimation(CrouchAnim)
local Camera = game.Workspace.CurrentCamera
local TweenService = game:GetService("TweenService")
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(key, gameProcessed)
if gameProcessed then return end
if key.KeyCode == Enum.KeyCode.LeftControl then
Humanoid.WalkSpeed = CrouchSpeed
Humanoid.JumpPower = 0
Humanoid.JumpHeight = 0
CAnim:Play()
CAnim.Looped = true
player.PlayerGui.StaminaAndHealth.SprintHandler.Enabled = false
end
end)
UIS.InputEnded:Connect(function(key, gameProcessed)
if gameProcessed then return end
if key.KeyCode == Enum.KeyCode.LeftControl then
Humanoid.WalkSpeed = NormalWalkSpeed
Humanoid.JumpPower = 50
Humanoid.JumpHeight = 7.2
CAnim:Stop()
CAnim.Looped = false
wait(1)
player.PlayerGui.StaminaAndHealth.SprintHandler.Enabled = true
end
end)
-------- Mobile Buttons
local function handleContext(name, state, input)
if state == Enum.UserInputState.Begin then
Humanoid.WalkSpeed = CrouchSpeed
CAnim:Play()
player.PlayerGui.StaminaAndHealth.SprintHandler.Enabled = false
CAnim.Looped = true
else
Humanoid.WalkSpeed = NormalWalkSpeed
CAnim:Stop()
CAnim.Looped = false
wait(1)
player.PlayerGui.StaminaAndHealth.SprintHandler.Enabled = true
end
end
cas:BindAction("Crouch", handleContext, true, Leftc, RightC)
cas:SetPosition("Crouch", UDim2.new(.2, 0, .5, 0))
cas:SetTitle("Crouch", "Crouch")
cas:GetButton("Crouch").Size = UDim2.new(.3, 0, .3, 0)