Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make a script for keybind crouch animation?

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.

3 comments

0

Please format your code properly

0

yes I did it @Twinbrotato

0

What happens when you run that code and press C? Any errors in output?

1 answer

✓ Accepted answer

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)


2 comments

0

sorry but you havent defined variable for player yet

0

Getting the local player, does not work in a server script. Only in a local script,

This discussion is preserved as it was. New answers, comments, and votes are closed.