local player = game.Players.LocalPlayer local humanoid = player.Character.Humanoid local UserInputService = game:GetService("UserInputService") local anim = Instance.new("Animation") anim.AnimationId = "5351326151" local LeftControl = Enum.KeyCode.LeftControl local function LeftControlDown() if UserInputService:IsKeyDown(LeftControl) then local PlayAnim = humanoid:LoadAnimation(anim) PlayAnim:Play() end end
Basically I am trying to replicate the Minecraft sneak mechanic where when you hold down a key it plays the crouching animation, and when you release it then you return to a stand animation. Any help would be greatly appreciated.
You would need to detect when the player begins pressing down the left control key by using UserInputService.KeyDown and that would make it begin to crouch. Then make sure the crouching animation is a looping animation. Then make it stop playing the crouching animation by using UserInputService.KeyReleased.
Just use the InputBegan event. Example:
local player = game.Players.LocalPlayer local humanoid = player.Character.Humanoid local UserInputService = game:GetService("UserInputService") local anim = Instance.new("Animation") anim.AnimationId = "5351326151" local LeftControl = Enum.KeyCode.LeftControl local function LeftControlDown(k) if k.KeyCode == LeftControl then -- If the key pressed is LeftControl local PlayAnim = humanoid:LoadAnimation(anim) PlayAnim:Play() end end UserInputService.InputBegan:Connect(LeftControlDown) -- The event for InputBegan
Hope this helps