In short
Put a LocalScript in StarterCharacterScripts. While C is held, lower Humanoid.HipHeight by about 1 stud, halve WalkSpeed, move Humanoid.CameraOffset down and play a looped crouch animation. On release, cast a block up from the root part with workspace:Blockcast; only stand up if nothing is in the way, otherwise try again next frame.
- HipHeight sets how high the root part floats above the floor, so lowering it makes the whole body, and its collision, shorter. That is what lets a crouched player fit under a gap.
- Without an animation the legs sink into the floor. Make a crouch animation in the Animation Editor and paste its ID into the script.
- Movement runs on the player's device, so a LocalScript is the right place. A server Script that changes HipHeight lags behind the player.
Get the script
Crouch script with ceiling check
One LocalScript in StarterCharacterScripts: hold C to crouch, walk at half speed with a lower camera, and stay crouched while something is overhead.
-- LocalScript in StarterCharacterScripts named Crouch.
-- Hold C (R3 on a gamepad) to crouch. On a phone, the Crouch button switches it on and off.
-- You stay crouched while something is above your head.
local ContextActionService = game:GetService("ContextActionService")
local RunService = game:GetService("RunService")
local HIP_DROP = 1.2 -- studs the body drops (R15 only)
local SPEED_MULTIPLIER = 0.5 -- crouched speed as a share of normal speed
local CROUCH_ANIMATION_ID = "" -- for example "rbxassetid://1234567890", or empty for none
local character = script.Parent :: Model
local humanoid = character:WaitForChild("Humanoid") :: Humanoid
local root = character:WaitForChild("HumanoidRootPart") :: BasePart
local head = character:WaitForChild("Head") :: BasePart
local isR15 = humanoid.RigType == Enum.HumanoidRigType.R15
local wantsCrouch = false -- the button is held (or toggled on, on a phone)
local crouching = false
local normalHipHeight = humanoid.HipHeight
local normalSpeed = humanoid.WalkSpeed
local headTop = 0 -- how far the top of the head is above the root part when standing
local track: AnimationTrack? = nil
if CROUCH_ANIMATION_ID ~= "" then
local animator = humanoid:WaitForChild("Animator") :: Animator
local animation = Instance.new("Animation")
animation.AnimationId = CROUCH_ANIMATION_ID
local loaded = animator:LoadAnimation(animation)
loaded.Looped = true
loaded.Priority = Enum.AnimationPriority.Action
track = loaded
end
-- The cast ignores the player's own body
local castParams = RaycastParams.new()
castParams.FilterType = Enum.RaycastFilterType.Exclude
castParams.FilterDescendantsInstances = { character }
-- True when there is room above the head to stand up
local function hasRoomToStand(): boolean
local needed = headTop + (if isR15 then HIP_DROP else 0)
local size = Vector3.new(root.Size.X, 0.2, root.Size.Z)
local start = CFrame.new(root.Position) -- flat box, no tilt
local hit = workspace:Blockcast(start, size, Vector3.new(0, needed, 0), castParams)
return hit == nil
end
local function startCrouch()
crouching = true
normalHipHeight = humanoid.HipHeight
normalSpeed = humanoid.WalkSpeed
headTop = (head.Position.Y + head.Size.Y / 2) - root.Position.Y
if isR15 then
humanoid.HipHeight = math.max(0, normalHipHeight - HIP_DROP)
end
humanoid.WalkSpeed = normalSpeed * SPEED_MULTIPLIER
humanoid.CameraOffset = Vector3.new(0, -HIP_DROP, 0)
if track then
track:Play(0.15)
end
character:SetAttribute("Crouching", true)
end
local function stopCrouch()
crouching = false
if isR15 then
humanoid.HipHeight = normalHipHeight
end
humanoid.WalkSpeed = normalSpeed
humanoid.CameraOffset = Vector3.zero
if track then
track:Stop(0.15)
end
character:SetAttribute("Crouching", false)
end
local function onCrouch(_name: string, state: Enum.UserInputState, input: InputObject): Enum.ContextActionResult
if input.UserInputType == Enum.UserInputType.Touch then
-- Holding a button on a phone is awkward, so a tap switches crouching on and off
if state == Enum.UserInputState.Begin then
wantsCrouch = not wantsCrouch
end
elseif state == Enum.UserInputState.Begin then
wantsCrouch = true
elseif state == Enum.UserInputState.End or state == Enum.UserInputState.Cancel then
wantsCrouch = false
end
return Enum.ContextActionResult.Pass
end
ContextActionService:BindAction("Crouch", onCrouch, true, Enum.KeyCode.C, Enum.KeyCode.ButtonR3)
ContextActionService:SetTitle("Crouch", "Crouch")
-- Every frame: crouch or stand to match the button, but only stand when there is room
local heartbeat = RunService.Heartbeat:Connect(function()
if humanoid.Health <= 0 then
return
end
if wantsCrouch and not crouching then
startCrouch()
elseif not wantsCrouch and crouching and hasRoomToStand() then
stopCrouch()
end
-- Freeze the crouch walk while standing still, so it looks like a crouched idle
if track and crouching then
track:AdjustSpeed(if humanoid.MoveDirection.Magnitude > 0 then 1 else 0)
end
end)
-- This script is removed with the character, so clean up the binding and the loop
humanoid.Died:Connect(function()
heartbeat:Disconnect()
ContextActionService:UnbindAction("Crouch")
end)
RoCode builds it in the place you have open in Roblox Studio, on Windows or macOS with a desktop browser; on a phone the button sends the prompt and the link to your computer. Free to start, with free credits every day. More Roblox Studio scripts
Where to put it
StarterPlayer
StarterCharacterScripts
Crouch LocalScript new
Settings you can change
HIP_DROPIn the script- Studs the body drops while crouching (R15). The camera drops the same amount. Default:
1.2. SPEED_MULTIPLIERIn the script- Walk speed while crouched, as a share of normal: 0.5 is half speed. Default:
0.5. CROUCH_ANIMATION_IDIn the script- Your crouch animation, such as
rbxassetid://1234567890. Leave it empty to crouch without an animation. Default: empty.
The script must be in StarterCharacterScripts: it uses script.Parent as the character, and a new copy for each life means a respawn always starts standing.
Type-checked with luau-lsp strict against Roblox's API definitions on 14 November 2026. Not playtested in Studio yet: press Play and watch the Output window before you publish.
Prompt for RoCode
Add crouching to my game: a LocalScript in StarterCharacterScripts that crouches while C or the gamepad R3 button is held, and toggles with a phone button. Crouching lowers HipHeight by 1.2 studs on R15, halves WalkSpeed, lowers the camera with CameraOffset, and plays a looped crouch animation if an ID is set. Use workspace:Blockcast from the root part so the player stays crouched while there is a ceiling above.
On this page
How crouching works in Roblox
A Roblox character stands on an invisible spring. The HumanoidRootPart floats a set distance above the floor, and that distance is Humanoid.HipHeight. Lower it and the root part, the torso and the head all move down. The character's collision shape gets shorter too, so it can walk under a gap it could not fit through standing.
| Property | Standing | Crouched |
|---|---|---|
Humanoid.HipHeight (R15) | About 2 for a default avatar | 1.2 lower |
Humanoid.WalkSpeed | 16 by default | Half |
Humanoid.CameraOffset | 0, 0, 0 | 1.2 studs down |
| Animation | Roblox's walk and idle | Your crouch animation, looped |
Step 1: Make a crouch animation (optional)
The script works without an animation, but the legs then sink into the floor because the body drops while the legs stay straight. An animation that bends the knees fixes that.
- On the Avatar tab, use the Rig Builder to insert an R15 rig.
- Open the Animation Editor on the same tab and select the rig. Make a pose with the knees bent and the hips about 1.2 studs lower, and add a second key with the same pose. The script loops the animation itself.
- Use the editor's menu to Publish to Roblox, to the account or group that owns your game, and copy the asset ID.
- Paste the ID into
CROUCH_ANIMATION_IDin Step 2, in the formrbxassetid://1234567890.
An animation can only play in a game owned by the same user or group that owns the animation. If your game belongs to a group, publish the animation to that group. The animation script guide covers this in more detail.
Step 2: The crouch LocalScript
- In the Explorer, expand StarterPlayer, hover over StarterCharacterScripts, click + and insert a LocalScript. Name it
Crouch. - Replace its contents with the code below. Paste your animation ID if you made one.
- Press Play and hold C.
-- LocalScript in StarterCharacterScripts named Crouch.
-- Hold C (R3 on a gamepad) to crouch. On a phone, the Crouch button switches it on and off.
-- You stay crouched while something is above your head.
local ContextActionService = game:GetService("ContextActionService")
local RunService = game:GetService("RunService")
local HIP_DROP = 1.2 -- studs the body drops (R15 only)
local SPEED_MULTIPLIER = 0.5 -- crouched speed as a share of normal speed
local CROUCH_ANIMATION_ID = "" -- for example "rbxassetid://1234567890", or empty for none
local character = script.Parent :: Model
local humanoid = character:WaitForChild("Humanoid") :: Humanoid
local root = character:WaitForChild("HumanoidRootPart") :: BasePart
local head = character:WaitForChild("Head") :: BasePart
local isR15 = humanoid.RigType == Enum.HumanoidRigType.R15
local wantsCrouch = false -- the button is held (or toggled on, on a phone)
local crouching = false
local normalHipHeight = humanoid.HipHeight
local normalSpeed = humanoid.WalkSpeed
local headTop = 0 -- how far the top of the head is above the root part when standing
local track: AnimationTrack? = nil
if CROUCH_ANIMATION_ID ~= "" then
local animator = humanoid:WaitForChild("Animator") :: Animator
local animation = Instance.new("Animation")
animation.AnimationId = CROUCH_ANIMATION_ID
local loaded = animator:LoadAnimation(animation)
loaded.Looped = true
loaded.Priority = Enum.AnimationPriority.Action
track = loaded
end
-- The cast ignores the player's own body
local castParams = RaycastParams.new()
castParams.FilterType = Enum.RaycastFilterType.Exclude
castParams.FilterDescendantsInstances = { character }
-- True when there is room above the head to stand up
local function hasRoomToStand(): boolean
local needed = headTop + (if isR15 then HIP_DROP else 0)
local size = Vector3.new(root.Size.X, 0.2, root.Size.Z)
local start = CFrame.new(root.Position) -- flat box, no tilt
local hit = workspace:Blockcast(start, size, Vector3.new(0, needed, 0), castParams)
return hit == nil
end
local function startCrouch()
crouching = true
normalHipHeight = humanoid.HipHeight
normalSpeed = humanoid.WalkSpeed
headTop = (head.Position.Y + head.Size.Y / 2) - root.Position.Y
if isR15 then
humanoid.HipHeight = math.max(0, normalHipHeight - HIP_DROP)
end
humanoid.WalkSpeed = normalSpeed * SPEED_MULTIPLIER
humanoid.CameraOffset = Vector3.new(0, -HIP_DROP, 0)
if track then
track:Play(0.15)
end
character:SetAttribute("Crouching", true)
end
local function stopCrouch()
crouching = false
if isR15 then
humanoid.HipHeight = normalHipHeight
end
humanoid.WalkSpeed = normalSpeed
humanoid.CameraOffset = Vector3.zero
if track then
track:Stop(0.15)
end
character:SetAttribute("Crouching", false)
end
local function onCrouch(_name: string, state: Enum.UserInputState, input: InputObject): Enum.ContextActionResult
if input.UserInputType == Enum.UserInputType.Touch then
-- Holding a button on a phone is awkward, so a tap switches crouching on and off
if state == Enum.UserInputState.Begin then
wantsCrouch = not wantsCrouch
end
elseif state == Enum.UserInputState.Begin then
wantsCrouch = true
elseif state == Enum.UserInputState.End or state == Enum.UserInputState.Cancel then
wantsCrouch = false
end
return Enum.ContextActionResult.Pass
end
ContextActionService:BindAction("Crouch", onCrouch, true, Enum.KeyCode.C, Enum.KeyCode.ButtonR3)
ContextActionService:SetTitle("Crouch", "Crouch")
-- Every frame: crouch or stand to match the button, but only stand when there is room
local heartbeat = RunService.Heartbeat:Connect(function()
if humanoid.Health <= 0 then
return
end
if wantsCrouch and not crouching then
startCrouch()
elseif not wantsCrouch and crouching and hasRoomToStand() then
stopCrouch()
end
-- Freeze the crouch walk while standing still, so it looks like a crouched idle
if track and crouching then
track:AdjustSpeed(if humanoid.MoveDirection.Magnitude > 0 then 1 else 0)
end
end)
-- This script is removed with the character, so clean up the binding and the loop
humanoid.Died:Connect(function()
heartbeat:Disconnect()
ContextActionService:UnbindAction("Crouch")
end)
The script sets a Crouching attribute on the character. Other LocalScripts can read it, for example to stop a sprint while crouched. It is set on the client, so it does not reach the server.
Step 3: How the ceiling check works
When the player lets go of C, the script does not stand up at once. Every frame it asks one question: is there room above the head? Only when the answer is yes does it put HipHeight back.
Measuring the space needed
At the moment the crouch starts, the player is still standing, so the script measures how far the top of the head is above the root part and saves it as headTop. Measuring the real avatar matters because avatars come in many heights. To stand back up, the root part rises by HIP_DROP, so the space needed above the crouched root part is headTop + HIP_DROP.
Blockcast instead of one ray
A single ray straight up from the middle of the body misses a beam that only covers the edge of the player's shoulders. workspace:Blockcast moves a whole box up instead. The box has the width and depth of the root part and is very thin, and it travels up by the space needed. If it hits a part or terrain on the way, the function returns a result and the player stays crouched.
Roblox's reference notes that a Blockcast does not detect parts the box is already inside when it starts. The box starts inside the player's own root part, which the RaycastParams exclude anyway, so this does not matter here. It would matter if the box started inside a wall.
Why speed is saved and restored
The script remembers the WalkSpeed at the moment the crouch starts and puts it back afterwards, instead of setting 16. A speed boost from a game pass or a speed pad is then kept. If another script changes WalkSpeed while the player is crouched, the crouch overwrites it when the player stands, so let only one script own WalkSpeed at a time. The sprint guide uses the same rule.
Step 4: Build a crouch-only gap
A crouch is easiest to test with a gap that only a crouched player fits through.
- Insert two Parts as walls about 6 studs apart and anchor them.
- Put a third anchored Part across the top of them as a ceiling, with its bottom just above the top of your character's head when crouched and below it when standing. About 4 studs above the floor is a good start for a default avatar.
- Press Play, hold C and walk under it. Let go of C halfway: you stay crouched until you leave the gap, then stand up.
If your players still bump into the ceiling while crouched, raise the ceiling a little or raise HIP_DROP. Avatars that are scaled up need more room.
Step 5: Test it
- Open the Output window (Window menu, then Output) and press Play.
- Hold C: the camera and body drop and you walk at half speed. Let go: you stand back up.
- Walk under the gap from Step 4 and let go of C underneath. You should stay crouched until you are out.
- Reset your character while crouched: the new character spawns standing at normal speed.
- To try the phone button, test with Studio's device emulator set to a phone. A tap crouches, a second tap stands.
Common errors and fixes
If holding C does nothing, check the Output window first: a red line names the script and the line.
The legs go into the floor
The body dropped but nothing bent the legs. Make a crouch animation (Step 1) and paste its ID into CROUCH_ANIMATION_ID.
The animation does not play
Check the ID format rbxassetid:// followed by the number, and that the animation is owned by the same user or group as the game. The Output window shows a warning when an animation fails to load.
The player stays crouched forever
Something is above the head within reach, for example an invisible part. If it should not block standing, untick its CanCollide and CanQuery (CanQuery only takes effect when CanCollide is off), or move it.
Crouching does nothing on R6
On R6 the script does not change HipHeight, because Roblox treats it differently there. Speed and camera still change. Use an R6 crouch animation for the pose.
Infinite yield possible on Head or HumanoidRootPart
The script is in the wrong place, or your custom character has no part with that name. Put it in StarterCharacterScripts. The infinite yield error page explains the warning.
Build it with RoCode
If you would rather not set this up by hand, RoCode can build it in the place you have open. RoCode is an independent AI agent for Roblox Studio, not made by Roblox: you describe the change in a web chat, and its Studio plugin creates the parts and scripts in your Explorer, so there is no code to paste.
Add crouching on C to my horror game, slow the player down while crouched, and add a vent the player can only get through by crouching.
- Can read your place first to find the scripts you already have, then adds the LocalScript next to them
- Writes the scripts with Create Script and is told to compile-check each one with Check Script
- Sets an undo point before and after each batch of changes, so Ctrl+Z steps back one batch at a time
After a build, RoCode can run its test robot: it plays your game in Studio and reports PASS or FAIL. It checks only what it chose to test, so crouch through your map yourself too. How RoCode connects to Studio.
Questions
How do you make a crouch script in Roblox Studio?
Use a LocalScript in StarterCharacterScripts that lowers Humanoid.HipHeight, slows WalkSpeed and moves CameraOffset down while C is held, then puts them back. Step 2 has the full script.
How do I make a crouch animation in Roblox?
Make a pose with bent knees in the Animation Editor, loop it, publish it and play it with Animator:LoadAnimation while the player crouches. Step 1 lists the steps.
How do I stop players standing up under a ceiling?
Before standing, cast a box up from the root part with workspace:Blockcast. If it hits something within the height needed, keep crouching and check again next frame.
Does the crouch script work on mobile?
Yes. BindAction with true adds a Crouch button on phones, and the script makes it a toggle.
Can I crouch to hide from NPCs?
Read the Crouching attribute from a LocalScript, or send it to the server with a RemoteEvent if a server-run NPC should react. The server should then check it with its own distance or raycast rules.
Sources and further reading
- Roblox Creator Docs: Humanoid. HipHeight and its R15 and R6 formulas, CameraOffset, WalkSpeed, RigType
- Roblox Creator Docs: WorldRoot. Blockcast and Raycast
- Roblox Creator Docs: AnimationTrack. Looped, Priority and AdjustSpeed
- Roblox Creator Docs: ContextActionService. BindAction and touch buttons
How the code was checked: every script on this page passes Luau's strict type checker against Roblox's API definitions (luau-lsp, 14 November 2026). A type check catches misspelt APIs and wrong types, not game logic, so playtest in Studio before you publish.