RB-004
Roblox sprint with shift script
Hold Left Shift to run faster. Let go to walk again.
- Script type
- LocalScript
- Where it goes
- StarterPlayer > StarterPlayerScripts
- Category
- Movement
For your own game in Roblox Studio. Not for use in other people's games.
The code
-- Sprint: hold the key to run faster. This is a LocalScript (it runs on the player's own device).
local WALK_SPEED = 16
local SPRINT_SPEED = 28
local SPRINT_KEY = Enum.KeyCode.LeftShift
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local player = Players.LocalPlayer
local function getHumanoid()
local character = player.Character
return character and character:FindFirstChildOfClass("Humanoid")
end
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then
return -- the player is typing in chat or using a menu
end
if input.KeyCode == SPRINT_KEY then
local humanoid = getHumanoid()
if humanoid then
humanoid.WalkSpeed = SPRINT_SPEED
end
end
end)
UserInputService.InputEnded:Connect(function(input)
if input.KeyCode == SPRINT_KEY then
local humanoid = getHumanoid()
if humanoid then
humanoid.WalkSpeed = WALK_SPEED
end
end
end)How to set it up
- In the Explorer, open StarterPlayer, then StarterPlayerScripts.
- Click the plus button next to StarterPlayerScripts and add a LocalScript.
- Paste the code into the LocalScript.
- Play and hold Left Shift while walking.
Change it
- This only works with a keyboard. Phone players need an on-screen button, which is a different script.
- Speed set on the player's device can be changed by a cheater. For a game where speed matters, move the check to the server.
- Change SPRINT_KEY to Enum.KeyCode.LeftControl or anything else you like.
More in Movement
More Roblox tools
- Shirt and pants templatesFree Roblox clothing templates to download: hoodies, jerseys, jeans, joggers and more.
- Robux tax calculatorWork out what you receive after the marketplace fee, or what to charge.
- Robux to USD calculatorConvert earned Robux to dollars at a DevEx rate you can edit.
- Shirt and pants template makerColour each panel of the 585×559 clothing template and download it.
- Username generatorGenerate usernames that fit the 3–20 character rule.