What execute you want to achieve?I want to make a manuscript that provides your personality crouch once you press C and also unCrouch as soon as you push C again, rather of the hold C to crouch.

You are watching: How to crouch in roblox

What is the issue?I don’t recognize what to search for come learn around the problem and its solution.What solutions have you tried for this reason far?As ns am a noob at scripting i tried count the C presses utilizing a variable and implementing them in the password . Yet as the script loops around, the variable gets initialized every time which brings me back to square one.

This is what the code looks like.

UserInputService.InputBegan:Connect(function(inputObject, processed)if processed then return end if inputObject.KeyCode == Enum.KeyCode.C thencrouchServerEvent:FireServer(player, Character)endend)UserInputService.InputBegan:Connect(function(inputObject, processed)if processed climate return finish if inputObject.KeyCode == Enum.KeyCode.C thenunCrouchServerEvent:FireServer(player, Character)endend)
do a debounce to determine if its ~ above crouching or uncrouching phase.

--like thislocal isCrouching = falseUserInputService.InputBegan:Connect(function(inputObject, processed)if processed then return finish if inputObject.KeyCode == Enum.KeyCode.C climate if isCrouching == false climate crouchServerEvent:FireServer(player, Character) isCrouching = true elseif isCrouching == true climate unCrouchServerEvent:FireServer(player, Character) isCrouching = false endendend)
You really wouldn’t have to fire a server event. All crouching go is play/stop an computer animation and adjust your HipHeight, both which are replicated on customer and server from LocalScripts.

Here’s a video similar to what you room trying come achieve: https://youtu.be/yGdQC-A5gVk


function CrouchFunc(_, inputState) if inputState == Enum.UserInputState.Begin then crouchServerEvent:FireServer(player, Character) else unCrouchServerEvent:FireServer(player, Character) endendContextActionService:BindAction("CrouchToggler", CrouchFunc, false, "c")Ideally, choose
SheriffTaco said, friend don’t need a FireServer in ~ all.

See more: Mike Sweeney For Congress - Candidate Profile Mike Sweeney


1 prefer
tonyredgraveX (tonyredgraveX) January 17, 2021, 12:46pm #5

Ideally i would usage animations for crouch… Ideally that is. Fact is my dumbass offered a script from toolbox that offers tweenmodule to make the the crouch and also prone. Ns didn’t protect against to inquiry why a crouch manuscript would be almost 400 present long. And also then i made that server-sided…so every the damages is done :’). Thanks a bunch because that the suggestions!edit1: ns forgot the word toggle existsedit2: over there is a surprising absence of sources on toggling inputs.


This script doesn’t toggle crouch however, it acts as organize crouch :o as it uncrouches after i let walk .