Full LocalScript local UIS = game:GetService("UserInputService") local Crouching = false local Character = script.Parent local Humanoid = Character:WaitForChild("Humanoid") local Animation = script.CrouchAnimation UIS.InputBegan:Connect(function(key) if key.KeyCode == Enum.KeyCode.C then if Crouching == false then Crouching = true LoadedAnimation = Humanoid:LoadAnimation(Animation) LoadedAnimation:Play() Humanoid.HipHeight -= 1.2 Humanoid.WalkSpeed = 8 Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false) else Crouching = false LoadedAnimation:Stop() Humanoid.HipHeight += 1.2 Humanoid.WalkSpeed = 16 Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true) end end end)
There is something going wrong for me, it also happened when i did the sliding animation from one of your videos too, whenever i press the button, nothing happens .
great video! one question though; when a player is crouching under something, if they uncrouch while still under it then they'll stand up inside of it and get stuck, unless they crouch again. how could you modify the code to make it so that when a player is underneath something, they're unable to press the button until they have adequate room above them to do so? thanks!
I can't get my code to work local UIS = game:GetService("UserInputService") local Crouching = false local Character = script.Parent local Humanoid = Character:WaitForChild("Humanoid") local Animation = script.CrouchAnimation UIS.InputBegan:Connect(function(key) if key.KeyCode == Enum.KeyCode.C then if Crouching == false then Crouching = true LoadedAnimation = Humanoid:LoadAnimation(Animation) LoadedAnimation:Play() Humanoid.HipHeight -= 1.2 Humanoid.WalkSpeed = 7 Humanoid:SetStateEnable(Enum.HumanoidStateType.Jumping, false) else Crouching = false LoadedAnimation = Humanoid:LoadAnimation(Animation) LoadedAnimation:Stop() Humanoid.HipHeight += 1.2 Humanoid.WalkSpeed = 16 Humanoid:SetStateEnable(Enum.HumanoidStateType.Jumping, true) end end end)
here is the script : local UIS = game:GetService("UserInputService") local UIS = game:GetService("UserInputService") local crouching = false local character = script.Parent local humanoid = character:WaitForChild("humanoid") local animation = script.crouchanimation UIS.InputBegan:Connect(function(key) if key.KeyCode == Enum.KeyCode.C then if crouching == false then crouching = true loadedanimation = humanoid:loadedanimation(animation) loadedanimation:play() humanoid.hipHeight -= 1.2 humanoid.walkspeed = 8 humanoid:setStateEnabled(Enum.HumanoidStateType,jumping, false) else crouching = false loadedanimation:stop() humanoid.hipHeight += 1.2 humanoid.walkspeed = 16 humanoid:setStateEnabled(Enum.HumanoidStateType,jumping, true) end end end)