Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a script for keybind crouch animation?

Asked by 4 years ago
Edited 4 years ago

I have my crouch Animation ready, But I don't know how to prepare a script for making it keybind. I I want it such that when I press 'c', I can crouch and when I press 'c' again, I can revert back to normal position. Can you please help me for giving me the script for that?

local player = game.Players.LocalPlayer
02  local mouse = player:GetMouse()
03  local Character = player.Character or player.CharacterAdded:Wait()
04  local Humanoid = Character:WaitForChild("Humanoid")
05  local UIS = game:GetService("UserInputService")
06   
07  local debounce = false
08  UIS.InputBegan:Connect(function(Input)
09      if Input.KeyCode == Enum.KeyCode.C then
10          if not debounce then
11              debounce = true
12              local Animation = Instance.new("Animation")
13              Animation.AnimationId = "rbxassetid://4851457147"
14              Animation.Parent = player.Character
15              Animate = Humanoid:LoadAnimation(Animation)
16              Animate:Play()
17          else
18              Animate:Stop()
19   
20              debounce = false
21          end
22      end 
23  end)

``

this is my current script and is not working.

0
Please format your code properly Twinbrotato 543 — 4y
0
yes I did it @Twinbrotato QuantumxGeneral 25 — 4y
0
What happens when you run that code and press C? Any errors in output? Twinbrotato 543 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Here's the script

local mouse = player:GetMouse()
local Animate 
local Humanoid = player.Character:FindFirstChild('Humanoid')
local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(io, gameProcessEvent) 
 if io.KeyCode == Enum.KeyCode.C then
  local Animation = Instance.new("Animation", player.Character)
  Animation.AnimationId = "rbxassetid://your id"
  Animate = Humanoid:LoadAnimation(Animation)
  Animate:Play()
 end  
end)
UIS.InputEnded:Connect(function(io, gameProcessEvent)
  if io.KeyCode == Enum.KeyCode.C then
  Animate:Stop()
 end
end)


0
sorry but you havent defined variable for player yet QuantumxGeneral 25 — 4y
0
Getting the local player, does not work in a server script. Only in a local script, maxpax2009 340 — 4y
Ad

Answer this question