Roblox sprint script (hold Shift to run)

Hold Shift to run, release to walk — with a sprint button on phones. One LocalScript, plus a stamina bar version.

LocalScriptUpdated November 2, 2026

Where to put it

LocalScript — StarterPlayer > StarterCharacterScripts > Sprint (LocalScript). It runs on each player's device.

  1. Insert a LocalScript into StarterPlayer → StarterCharacterScripts and paste the code. It runs again for every new character.

The script

StarterPlayer > StarterCharacterScripts > Sprint (LocalScript)
local ContextActionService = game:GetService("ContextActionService")

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

local WALK_SPEED = 16
local SPRINT_SPEED = 26

local function onSprint(_, state)
	if state == Enum.UserInputState.Begin then
		humanoid.WalkSpeed = SPRINT_SPEED
	elseif state == Enum.UserInputState.End or state == Enum.UserInputState.Cancel then
		humanoid.WalkSpeed = WALK_SPEED
	end
	return Enum.ContextActionResult.Pass
end

-- "true" adds a touch button on phones and tablets.
ContextActionService:BindAction("Sprint", onSprint, true, Enum.KeyCode.LeftShift)
ContextActionService:SetTitle("Sprint", "Run")

How it works

  • Players control their own character's movement, so changing WalkSpeed in a LocalScript works and replicates.
  • ContextActionService handles Shift on keyboards and adds a button on touch devices.
  • Scripts in StarterCharacterScripts are copied into each new character, so sprint works after respawning.

Variations

Stamina

Running drains stamina; at 0 the player slows down until it refills. Show stamina on a Frame's size for a bar.

local RunService = game:GetService("RunService")
local stamina, sprinting = 100, false
-- in onSprint: set sprinting = true / false instead of WalkSpeed

RunService.Heartbeat:Connect(function(dt)
	if sprinting and stamina > 0 and humanoid.MoveDirection.Magnitude > 0 then
		stamina = math.max(stamina - 25 * dt, 0)
	else
		stamina = math.min(stamina + 15 * dt, 100)
	end
	humanoid.WalkSpeed = (sprinting and stamina > 0) and SPRINT_SPEED or WALK_SPEED
end)

Common mistakes

  • Putting the LocalScript in ServerScriptService — LocalScripts don't run there.
  • Using Shift-lock games without rebinding: Left Shift may toggle Shift Lock. Use Left Ctrl or turn off Shift Lock in Game Settings if they clash.
  • Trusting speed for anti-cheat: exploiters can change their own WalkSpeed, so check movement on the server if speed matters for winning.

FAQ

Why doesn't my sprint script work after I die?

Put it in StarterCharacterScripts so it is copied into every new character, or reconnect it on CharacterAdded.

How do I add a sprint button for mobile?

Bind the action with ContextActionService:BindAction and pass true as the third argument; Roblox creates the button on touch screens.

Keep reading